]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cache: forward data with headers
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 14 Nov 2017 13:39:23 +0000 (14:39 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 14 Nov 2017 14:20:44 +0000 (15:20 +0100)
Forward the remaining headers with the data in the first call of
cache_store_http_forward_data().

Previously the headers were forwarded first, and the function left,
implying an additionnal call to cache_store_http_forward_data() for the
data.

Cc: Christopher Faulet <cfaulet@haproxy.com>
src/cache.c

index 26d9b12af07e745acb8656ec1d5ad3772f1f69e5..c27ed8a5570841d0a853228c2f720c6f262e4e0e 100644 (file)
@@ -161,40 +161,33 @@ cache_store_http_forward_data(struct stream *s, struct filter *filter,
                /* Nothing to foward */
                ret = len;
        }
-       else if (st->hdrs_len > len) {
+       else if (st->hdrs_len >= len) {
                /* Forward part of headers */
                ret           = len;
                st->hdrs_len -= len;
        }
-       else if (st->hdrs_len > 0) {
-               /* Forward remaining headers */
-               ret          = st->hdrs_len;
-               st->hdrs_len = 0;
-       }
        else {
-               /* Forward trailers data */
+               /* Forward data */
                if (filter->ctx && st->first_block) {
                        /* disable buffering if too much data (never greater than a buffer size */
-                       if (len > global.tune.bufsize - global.tune.maxrewrite - st->first_block->len) {
+                       if (len - st->hdrs_len > global.tune.bufsize - global.tune.maxrewrite - st->first_block->len) {
                                filter->ctx = NULL; /* disable cache  */
                                shctx_lock(shctx);
                                shctx_row_dec_hot(shctx, st->first_block);
                                shctx_unlock(shctx);
                                pool_free2(pool2_cache_st, st);
-                               ret = 0;
                        } else {
-
-                               int blen;
-                               blen = shctx_row_data_append(shctx,
-                                   st->first_block,
-                                   (unsigned char *)bi_ptr(msg->chn->buf),
-                                   MIN(bi_contig_data(msg->chn->buf), len));
-
-                               ret = MIN(bi_contig_data(msg->chn->buf), len) + blen;
+                               /* Skip remaining headers to fill the cache */
+                               b_adv(msg->chn->buf, st->hdrs_len);
+                               ret = shctx_row_data_append(shctx,
+                                                           st->first_block,
+                                                           (unsigned char *)bi_ptr(msg->chn->buf),
+                                                           MIN(bi_contig_data(msg->chn->buf), len - st->hdrs_len));
+                               /* Rewind the buffer to forward all data */
+                               b_rew(msg->chn->buf, st->hdrs_len);
                        }
-               } else {
-                       ret = len;
                }
+               ret = len;
        }
 
        if ((ret != len) ||