From: Vsevolod Stakhov Date: Mon, 6 Feb 2017 14:16:10 +0000 (+0000) Subject: [Feature] Allow to specify custom method for a message X-Git-Tag: 1.5.0~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=549b0ecd86189b061c32be7d91d0498851965bd9;p=thirdparty%2Frspamd.git [Feature] Allow to specify custom method for a message --- diff --git a/src/libutil/http.c b/src/libutil/http.c index 649cebeb22..deddc56a41 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -2455,6 +2455,20 @@ rspamd_http_message_set_body (struct rspamd_http_message *msg, return TRUE; } +void +rspamd_http_message_set_method (struct rspamd_http_message *msg, + const gchar *method) +{ + gint i; + + /* Linear search: not very efficient method */ + for (i = 0; i < HTTP_METHOD_MAX; i ++) { + if (g_ascii_strcasecmp (method, http_method_str (i)) == 0) { + msg->method = i; + } + } +} + gboolean rspamd_http_message_set_body_from_fd (struct rspamd_http_message *msg, gint fd) diff --git a/src/libutil/http.h b/src/libutil/http.h index a28a6b3895..23d2fa3faf 100644 --- a/src/libutil/http.h +++ b/src/libutil/http.h @@ -333,6 +333,13 @@ const gchar *rspamd_http_message_get_body (struct rspamd_http_message *msg, gboolean rspamd_http_message_set_body (struct rspamd_http_message *msg, const gchar *data, gsize len); +/** + * Set message's method by name + * @param msg + * @param method + */ +void rspamd_http_message_set_method (struct rspamd_http_message *msg, + const gchar *method); /** * Maps fd as message's body * @param msg diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index ab389cb829..31b0b3be3a 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -578,6 +578,15 @@ lua_http_request (lua_State *L) } lua_pop (L, 1); + + lua_pushstring (L, "method"); + lua_gettable (L, 1); + + if (lua_type (L, -1) == LUA_TSTRING) { + rspamd_http_message_set_method (msg, lua_tostring (L, -1)); + } + + lua_pop (L, 1); } else { msg_err ("http request has bad params");