: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.
+ :param integer request.timeout: Optional timeout parameter, set a "timeout server" on the connections.
:returns: Lua table containing the response
} ops;
struct sockaddr_storage *dst; /* destination address */
struct appctx *appctx; /* HTTPclient appctx */
+ int timeout_server; /* server timeout in ms */
void *caller; /* ptr of the caller */
unsigned int flags; /* other flags */
};
struct appctx *httpclient_start(struct httpclient *hc);
int httpclient_set_dst(struct httpclient *hc, const char *dst);
+void httpclient_set_timeout(struct httpclient *hc, int timeout);
int httpclient_res_xfer(struct httpclient *hc, struct buffer *dst);
int httpclient_req_gen(struct httpclient *hc, const struct ist url, enum http_meth_t meth, const struct http_hdr *hdrs, const struct ist payload);
int httpclient_req_xfer(struct httpclient *hc, struct ist src, int end);
struct hlua *hlua;
const char *url_str = NULL;
const char *body_str = NULL;
+ int timeout;
size_t buf_len;
int ret;
}
lua_pop(L, 1);
+ ret = lua_getfield(L, -1, "timeout");
+ if (ret == LUA_TNUMBER) {
+ timeout = lua_tointeger(L, -1);
+ httpclient_set_timeout(hlua_hc->hc, timeout);
+ }
+
ret = lua_getfield(L, -1, "headers");
if (ret == LUA_TTABLE) {
hdrs = hlua_httpclient_table_to_hdrs(L);
return ret;
}
+/* Set the 'timeout server' in ms for the next httpclient request */
+void httpclient_set_timeout(struct httpclient *hc, int timeout)
+{
+ hc->timeout_server = timeout;
+}
+
/*
* Sets a destination for the httpclient from an HAProxy addr format
* This will prevent to determine the destination from the URL
goto out_free_appctx;
}
+ /* set the "timeout server" */
+ s->req.wto = hc->timeout_server;
+ s->res.rto = hc->timeout_server;
+
/* if httpclient_set_dst() was used, sets the alternative address */
if (hc->dst)
ss_dst = hc->dst;