From 4b490b8af5704d3310727b13f87c5e8890ce18a4 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 25 Nov 2020 08:08:08 +0100 Subject: [PATCH] BUG/MINOR: http-fetch: Fix smp_fetch_body() when called from a health-check res.body may be called from a health-check. It is probably never used. But it is possibe. In such case, there is no channel. Thus we must not use it unconditionally to set the flag SMP_F_MAY_CHANGE on the smp. Now the condition test the channel first. In addtion, the flag is not set if the payload is fully received. This patch must be backported as far as 2.2. (cherry picked from commit a9ffc416377e0df9859526dc3c1d769c6a68636f) Signed-off-by: William Lallemand --- src/http_fetch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/http_fetch.c b/src/http_fetch.c index 595e0e3..a0b9cf5 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -587,6 +587,7 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char struct htx *htx = smp_prefetch_htx(smp, chn, check, 1); struct buffer *temp; int32_t pos; + int finished = 0; if (!htx) return 0; @@ -596,8 +597,10 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char struct htx_blk *blk = htx_get_blk(htx, pos); enum htx_blk_type type = htx_get_blk_type(blk); - if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) + if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) { + finished = 1; break; + } if (type == HTX_BLK_DATA) { if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0)) return 0; @@ -608,7 +611,8 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char smp->data.u.str = *temp; smp->flags = SMP_F_VOL_TEST; - if (!channel_full(chn, global.tune.maxrewrite) && !(chn->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR))) + if (!finished && (check || (chn && !channel_full(chn, global.tune.maxrewrite) && + !(chn->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR))))) smp->flags |= SMP_F_MAY_CHANGE; return 1; -- 1.7.10.4