diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index bf96a47b48..9aed82c4a2 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -1869,13 +1869,14 @@ HTTPClient class
:param string request.url: Is a mandatory parameter for the request that contains the URL.
:param string request.body: Is an optional parameter for the request that contains the body to send.
:param table request.headers: Is an optional parameter for the request that contains the headers to send.
+ :param table request.dst: Is an optional parameter for the destination in haproxy address format.
:returns: Lua table containing the response
.. code-block:: lua
local httpclient = core.httpclient()
- local response = httpclient:post{url="http://127.0.0.1", body=body}
+ local response = httpclient:post{url="http://127.0.0.1", body=body, dst="unix@/var/run/http.sock"}
..
@@ -1888,7 +1889,7 @@ HTTPClient class
["content-type"] = { "text/html" },
["cache-control"] = { "no-cache", "no-store" },
},
- body = "
invalid request"
+ body = "invalid request",
}
..
diff --git a/reg-tests/lua/lua_httpclient.lua b/reg-tests/lua/lua_httpclient.lua
index e9ec0f02c7..b5a5180c12 100644
--- a/reg-tests/lua/lua_httpclient.lua
+++ b/reg-tests/lua/lua_httpclient.lua
@@ -42,7 +42,7 @@ local function cron()
core.Info("Third httpclient request")
local httpclient3 = core.httpclient()
- local response3 = httpclient3:get{url="http://127.0.0.1:" .. vtc_port3, headers={ [ "Host" ] = { "foobar.haproxy.local" } }}
+ local response3 = httpclient3:get{url="http://127.0.0.1", dst = vtc_port3, headers={ [ "Host" ] = { "foobar.haproxy.local" } }}
end
diff --git a/reg-tests/lua/lua_httpclient.vtc b/reg-tests/lua/lua_httpclient.vtc
index 7c55d54bf3..0850ddb5f3 100644
--- a/reg-tests/lua/lua_httpclient.vtc
+++ b/reg-tests/lua/lua_httpclient.vtc
@@ -49,10 +49,15 @@ haproxy h1 -conf {
mode http
http-request use-service lua.fakeserv
+ listen li1
+ mode http
+ bind unix@${testdir}/srv3
+ server srv3 ${s3_addr}:${s3_port}
+
} -start
client c0 -connect ${h1_fe1_sock} {
- txreq -url "/" -hdr "vtcport: ${s1_port}" -hdr "vtcport2: ${s2_port}" -hdr "vtcport3: ${s3_port}"
+ txreq -url "/" -hdr "vtcport: ${s1_port}" -hdr "vtcport2: ${s2_port}" -hdr "vtcport3: unix@${testdir}/srv3"
rxresp
expect resp.status == 200
} -run
diff --git a/src/hlua.c b/src/hlua.c
index 06d4ce0c39..0098d02b8f 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -7230,6 +7230,15 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
if (lua_gettop(L) != 2 || lua_type(L, -1) != LUA_TTABLE)
WILL_LJMP(luaL_error(L, "'get' needs a table as argument"));
+ hlua_hc = hlua_checkhttpclient(L, 1);
+
+ ret = lua_getfield(L, -1, "dst");
+ if (ret == LUA_TSTRING) {
+ if (httpclient_set_dst(hlua_hc->hc, lua_tostring(L, -1)) < 0)
+ WILL_LJMP(luaL_error(L, "Can't use the 'dst' argument"));
+ }
+ lua_pop(L, 1);
+
ret = lua_getfield(L, -1, "url");
if (ret == LUA_TSTRING) {
url_str = lua_tostring(L, -1);
@@ -7254,7 +7263,6 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
return 0;
}
- hlua_hc = hlua_checkhttpclient(L, 1);
hlua_hc->hc->req.url = istdup(ist(url_str));
hlua_hc->hc->req.meth = meth;