]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http-fetch: Fix smp_fetch_body() when called from a health-check
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 25 Nov 2020 07:08:08 +0000 (08:08 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Nov 2020 09:30:23 +0000 (10:30 +0100)
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.

src/http_fetch.c

index 595e0e31898776a775b8707241876731f529f830..a0b9cf57ffe0b9d060e21f8335dde16882751732 100644 (file)
@@ -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;