MINOR: httpclient/lua: return an error when it can't generate the request
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 26 Oct 2021 13:01:53 +0000 (15:01 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 27 Oct 2021 08:19:58 +0000 (10:19 +0200)
Add a check during the httpclient request generation which yield an lua
error when the generation didn't work. The most common case is the lack
of space in the buffer, it can because of too much headers or a too big
body.

src/hlua.c

index d3c7684..27c6216 100644 (file)
@@ -7209,8 +7209,7 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
        hlua_hc->hc->ops.res_end = hlua_httpclient_res_cb;
 
 
-       httpclient_req_gen(hlua_hc->hc, hlua_hc->hc->req.url, meth, hdrs, ist(body_str));
-       httpclient_start(hlua_hc->hc);
+       ret = httpclient_req_gen(hlua_hc->hc, hlua_hc->hc->req.url, meth, hdrs, ist(body_str));
 
        /* free the temporary headers array */
        hdrs_i = hdrs;
@@ -7222,6 +7221,13 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
        ha_free(&hdrs);
 
 
+       if (ret != ERR_NONE) {
+               WILL_LJMP(luaL_error(L, "Can't generate the HTTP request"));
+               return 0;
+       }
+
+
+       httpclient_start(hlua_hc->hc);
 
        /* we return a "res" object */
        lua_newtable(L);