]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: httpclient/lua: Don't set req_payload callback if body is empty
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 14 Oct 2022 12:57:04 +0000 (14:57 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 14 Oct 2022 13:18:25 +0000 (15:18 +0200)
The HTTPclient callback req_payload callback is set when a request payload
must be streamed. In the lua, this callback is set when a body is passed as
argument in one of httpclient functions (head/get/post/put/delete). However,
there is no reason to set it if body string is empty.

This patch is related to the issue #1898. It may be backported as far as
2.5.

src/hlua.c

index ccdf5389664c9751c7dc5df554aec95824bf2ed2..70be127f1ac657dba8eea526e36290adf43cf5bd 100644 (file)
@@ -7312,7 +7312,7 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
        struct hlua *hlua;
        const char *url_str = NULL;
        const char *body_str = NULL;
-       size_t buf_len;
+       size_t buf_len = 0;
        int ret;
 
        hlua = hlua_gethlua(L);
@@ -7376,7 +7376,7 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
        hlua_hc->hc->ops.res_end = hlua_httpclient_cb;
 
        /* a body is available, it will use the request callback */
-       if (body_str) {
+       if (body_str && buf_len) {
                hlua_hc->hc->ops.req_payload = hlua_httpclient_cb;
        }