]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http: only allocate the temporary compression buffer when needed
authorWilly Tarreau <w@1wt.eu>
Mon, 21 Apr 2014 09:27:29 +0000 (11:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Apr 2014 21:15:29 +0000 (23:15 +0200)
Since we know when the buffer is needed, only check for its allocation
at the same place in order to avoid useless tests on the normal path.

src/proto_http.c

index 114efef89d9d96f99b2236438979f09ee5b2c53c..680e15a0eeea15081629d588ea0735d7f79c2ecb 100644 (file)
@@ -6179,12 +6179,6 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
        /* in most states, we should abort in case of early close */
        channel_auto_close(res);
 
-       /* this is the first time we need the compression buffer */
-       if (s->comp_algo != NULL && tmpbuf == NULL) {
-               if ((tmpbuf = pool_alloc2(pool2_buffer)) == NULL)
-                       goto aborted_xfer; /* no memory */
-       }
-
        if (msg->sov) {
                /* we have msg->sov which points to the first byte of message
                 * body, and res->buf.p still points to the beginning of the
@@ -6207,8 +6201,19 @@ int http_response_forward_body(struct session *s, struct channel *res, int an_bi
                }
        }
 
-       if (s->comp_algo != NULL && msg->msg_state < HTTP_MSG_TRAILERS) {
-               ret = http_compression_buffer_init(s, res->buf, tmpbuf); /* init a buffer with headers */
+       if (unlikely(s->comp_algo != NULL) && msg->msg_state < HTTP_MSG_TRAILERS) {
+               /* We need a compression buffer in the DATA state to put the
+                * output of compressed data, and in CRLF state to let the
+                * TRAILERS state finish the job of removing the trailing CRLF.
+                */
+               if (unlikely(tmpbuf == NULL)) {
+                       /* this is the first time we need the compression buffer */
+                       tmpbuf = pool_alloc2(pool2_buffer);
+                       if (tmpbuf == NULL)
+                               goto aborted_xfer; /* no memory */
+               }
+
+               ret = http_compression_buffer_init(s, res->buf, tmpbuf);
                if (ret < 0) {
                        res->flags |= CF_WAKE_WRITE;
                        goto missing_data; /* not enough spaces in buffers */