From 10935bc547539001f2a35a0d9e0073787320b6f1 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Tue, 14 Nov 2017 14:39:23 +0100 Subject: [PATCH] MINOR: cache: forward data with headers 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 --- src/cache.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/cache.c b/src/cache.c index 26d9b12af..c27ed8a55 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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) ||