summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-02-06 14:16:10 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-02-06 14:16:10 +0000
commit549b0ecd86189b061c32be7d91d0498851965bd9 (patch)
treed7aa2c291fa23e439466fb1bd5cc2cf5bddade82
parent05da599c5908e80dc5f569b43ba891af80fbe0fa (diff)
downloadrspamd-549b0ecd86189b061c32be7d91d0498851965bd9.tar.gz
rspamd-549b0ecd86189b061c32be7d91d0498851965bd9.zip
[Feature] Allow to specify custom method for a message
-rw-r--r--src/libutil/http.c14
-rw-r--r--src/libutil/http.h7
-rw-r--r--src/lua/lua_http.c9
3 files changed, 30 insertions, 0 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c
index 649cebeb2..deddc56a4 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 a28a6b389..23d2fa3fa 100644
--- a/src/libutil/http.h
+++ b/src/libutil/http.h
@@ -334,6 +334,13 @@ 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
* @param fd
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index ab389cb82..31b0b3be3 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");