mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-10 00:57:02 +02:00
head-truc
This commit is contained in:
parent
538f3e04b5
commit
7d21836bc6
66
src/hlua.c
66
src/hlua.c
@ -7007,7 +7007,7 @@ __LJMP static int hlua_httpclient_get_headers(lua_State *L, struct hlua_httpclie
|
|||||||
* in the lua buffer, once the httpclient finished its job, push the result on
|
* in the lua buffer, once the httpclient finished its job, push the result on
|
||||||
* the stack
|
* the stack
|
||||||
*/
|
*/
|
||||||
__LJMP static int hlua_httpclient_get_yield(lua_State *L, int status, lua_KContext ctx)
|
__LJMP static int hlua_httpclient_send_yield(lua_State *L, int status, lua_KContext ctx)
|
||||||
{
|
{
|
||||||
struct buffer *tr;
|
struct buffer *tr;
|
||||||
int res;
|
int res;
|
||||||
@ -7045,17 +7045,15 @@ __LJMP static int hlua_httpclient_get_yield(lua_State *L, int status, lua_KConte
|
|||||||
task_wakeup(hlua->task, TASK_WOKEN_MSG);
|
task_wakeup(hlua->task, TASK_WOKEN_MSG);
|
||||||
|
|
||||||
|
|
||||||
MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_httpclient_get_yield, TICK_ETERNITY, 0));
|
MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_httpclient_send_yield, TICK_ETERNITY, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sends and receive an HTTP request
|
* Send an HTTP request and wait for a response
|
||||||
*
|
|
||||||
* httpclient.get(url, headers)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
__LJMP static int hlua_httpclient_get(lua_State *L)
|
__LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
|
||||||
{
|
{
|
||||||
struct hlua_httpclient *hlua_hc;
|
struct hlua_httpclient *hlua_hc;
|
||||||
struct hlua *hlua;
|
struct hlua *hlua;
|
||||||
@ -7101,6 +7099,58 @@ __LJMP static int hlua_httpclient_get(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sends an HTTP HEAD request and wait for a response
|
||||||
|
*
|
||||||
|
* httpclient:head(url, headers, payload)
|
||||||
|
*/
|
||||||
|
__LJMP static int hlua_httpclient_head(lua_State *L)
|
||||||
|
{
|
||||||
|
return hlua_httpclient_send(L, HTTP_METH_HEAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send an HTTP GET request and wait for a response
|
||||||
|
*
|
||||||
|
* httpclient:get(url, headers, payload)
|
||||||
|
*/
|
||||||
|
__LJMP static int hlua_httpclient_get(lua_State *L)
|
||||||
|
{
|
||||||
|
return hlua_httpclient_send(L, HTTP_METH_GET);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sends an HTTP PUT request and wait for a response
|
||||||
|
*
|
||||||
|
* httpclient:put(url, headers, payload)
|
||||||
|
*/
|
||||||
|
__LJMP static int hlua_httpclient_put(lua_State *L)
|
||||||
|
{
|
||||||
|
return hlua_httpclient_send(L, HTTP_METH_PUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send an HTTP POST request and wait for a response
|
||||||
|
*
|
||||||
|
* httpclient:post(url, headers, payload)
|
||||||
|
*/
|
||||||
|
__LJMP static int hlua_httpclient_post(lua_State *L)
|
||||||
|
{
|
||||||
|
return hlua_httpclient_send(L, HTTP_METH_POST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sends an HTTP HEAD request and wait for a response
|
||||||
|
*
|
||||||
|
* httpclient:delete(url, headers, payload)
|
||||||
|
*/
|
||||||
|
__LJMP static int hlua_httpclient_delete(lua_State *L)
|
||||||
|
{
|
||||||
|
return hlua_httpclient_send(L, HTTP_METH_DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -11747,6 +11797,10 @@ lua_State *hlua_init_state(int thread_num)
|
|||||||
lua_pushstring(L, "__index");
|
lua_pushstring(L, "__index");
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
hlua_class_function(L, "get", hlua_httpclient_get);
|
hlua_class_function(L, "get", hlua_httpclient_get);
|
||||||
|
hlua_class_function(L, "head", hlua_httpclient_head);
|
||||||
|
hlua_class_function(L, "put", hlua_httpclient_put);
|
||||||
|
hlua_class_function(L, "post", hlua_httpclient_post);
|
||||||
|
hlua_class_function(L, "delete", hlua_httpclient_delete);
|
||||||
lua_settable(L, -3); /* Sets the __index entry. */
|
lua_settable(L, -3); /* Sets the __index entry. */
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user