]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: http-client: Test HTX_FL_EOM flag before commiting the HTX buffer
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 8 Jul 2025 06:24:45 +0000 (08:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 9 Jul 2025 14:27:24 +0000 (16:27 +0200)
when htx_to_buf() function is called, if the HTX message is empty, the
buffer is reset. So HTX flags must not be tested after because the info may
be lost.

So now, we take care to test HTX_FL_EOM flag before calling htx_to_buf().

This patch must be backported as far as 2.8.

src/http_client.c

index 7d14ed267f061170535199da1ec67dbb665d9f2d..809e437d590e4406079c7e9d7721030dd9c7ba74 100644 (file)
@@ -659,8 +659,6 @@ void httpclient_applet_io_handler(struct appctx *appctx)
                                if (hc->ops.res_stline)
                                        hc->ops.res_stline(hc);
 
-                               htx_to_buf(htx, &res->buf);
-
                                /* if there is no HTX data anymore and the EOM flag is
                                 * set, leave (no body) */
                                if (htx_is_empty(htx) && htx->flags & HTX_FL_EOM)
@@ -668,6 +666,7 @@ void httpclient_applet_io_handler(struct appctx *appctx)
                                else
                                        appctx->st0 = HTTPCLIENT_S_RES_HDR;
 
+                               htx_to_buf(htx, &res->buf);
                                break;
 
                        case HTTPCLIENT_S_RES_HDR:
@@ -697,7 +696,6 @@ void httpclient_applet_io_handler(struct appctx *appctx)
                                        if (htx->flags & HTX_FL_EOM)
                                                hc_htx->flags |= HTX_FL_EOM;
 
-                                       htx_to_buf(htx, &res->buf);
                                        htx_to_buf(hc_htx, &hc->res.buf);
 
                                } else {
@@ -730,7 +728,6 @@ void httpclient_applet_io_handler(struct appctx *appctx)
                                                }
                                                blk = htx_remove_blk(htx, blk);
                                        }
-                                       htx_to_buf(htx, &res->buf);
 
                                        if (hdr_num) {
                                                /* alloc and copy the headers in the httpclient struct */
@@ -752,6 +749,7 @@ void httpclient_applet_io_handler(struct appctx *appctx)
                                        appctx->st0 = HTTPCLIENT_S_RES_BODY;
                                }
 
+                               htx_to_buf(htx, &res->buf);
                                break;
 
                        case HTTPCLIENT_S_RES_BODY:
@@ -841,16 +839,16 @@ void httpclient_applet_io_handler(struct appctx *appctx)
                                        }
                                }
 
+                               /* if not finished, should be called again */
+                               if ((htx_is_empty(htx) && (htx->flags & HTX_FL_EOM)))
+                                       appctx->st0 = HTTPCLIENT_S_RES_END;
+
                                htx_to_buf(htx, &res->buf);
 
                                /* the data must be processed by the caller in the receive phase */
                                if (hc->ops.res_payload)
                                        hc->ops.res_payload(hc);
 
-                               /* if not finished, should be called again */
-                               if ((htx_is_empty(htx) && (htx->flags & HTX_FL_EOM)))
-                                       appctx->st0 = HTTPCLIENT_S_RES_END;
-                               /* end of message, we should quit */
                                break;
 
                        case HTTPCLIENT_S_RES_END: