BUG/MINOR: h1-htx: Use default reason if not set when formatting the response
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 29 Nov 2024 13:31:21 +0000 (14:31 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 11 Dec 2024 13:43:16 +0000 (14:43 +0100)
When the response status line is formatted before sending it to the client,
if there is no reason set, HAProxy should add one that matches the status
code, as stated in the configuration manual. However it is not performed.

It is possible to hit this bug when the response comes from a H2 server,
because there is no reason field in HTTP/2 and above.

This patch should fix the issue #2798. It should be backported to all stable
versions.

(cherry picked from commit 37487ada739fc86e3acb46c9949196f4f15cc9b1)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 736d4e2c3550dc9c56e5f05778457466b3ce13d9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/h1_htx.c

index 768d0f0..6e2c67a 100644 (file)
@@ -984,6 +984,7 @@ int h1_format_htx_reqline(const struct htx_sl *sl, struct buffer *chk)
 int h1_format_htx_stline(const struct htx_sl *sl, struct buffer *chk)
 {
        size_t sz = chk->data;
+       struct ist reason;
 
        if (HTX_SL_LEN(sl) + 4 > b_room(chk))
                return 0;
@@ -996,10 +997,15 @@ int h1_format_htx_stline(const struct htx_sl *sl, struct buffer *chk)
                if (!chunk_memcat(chk, HTX_SL_RES_VPTR(sl), HTX_SL_RES_VLEN(sl)))
                        goto full;
        }
+
+       reason = htx_sl_res_reason(sl);
+       if (istlen(reason) == 0)
+               reason = ist(http_get_reason(sl->info.res.status));
+
        if (!chunk_memcat(chk, " ", 1) ||
            !chunk_memcat(chk, HTX_SL_RES_CPTR(sl), HTX_SL_RES_CLEN(sl)) ||
            !chunk_memcat(chk, " ", 1) ||
-           !chunk_memcat(chk, HTX_SL_RES_RPTR(sl), HTX_SL_RES_RLEN(sl)) ||
+           !chunk_memcat(chk, istptr(reason), istlen(reason)) ||
            !chunk_memcat(chk, "\r\n", 2))
                goto full;