]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: httpclient: add a Content-Length when the payload is known
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 4 Jul 2025 07:05:21 +0000 (09:05 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 4 Jul 2025 13:21:50 +0000 (15:21 +0200)
This introduce a change of behavior in the httpclient API. When
generating a request with a payload buffer, the size of the buffer
payload is known and does not need to be streamed in chunks.

This patch force to sends payload buffer using a Content-Length header
in the request, however the behavior does not change if a callback is
still used instead of a buffer.

src/http_client.c

index 0bd992d78a5bf645f2722e98a6412e68f9ddfc4b..f061b230b45475b3713f3bbefc6a1b6e3e190d62 100644 (file)
@@ -136,13 +136,20 @@ int httpclient_req_gen(struct httpclient *hc, const struct ist url, enum http_me
                        goto error;
        }
 
+       if (isttest(payload) && istlen(payload)) {
+               /* add the Content-Length of the payload when not using the callback */
+
+               if (!htx_add_header(htx, ist("Content-Length"), ist(ultoa(istlen(payload)))))
+                       goto error;
+
+       }
 
        if (!htx_add_endof(htx, HTX_BLK_EOH))
                goto error;
 
        if (isttest(payload) && istlen(payload)) {
-               /* add the payload if it can feat in the buffer, no need to set
-                * the Content-Length, the data will be sent chunked */
+               /* add the payload if it can feat in the buffer, Content-Length was added before */
+
                if (!htx_add_data_atonce(htx, payload))
                        goto error;
        }