#include "lua_common.h"
#include "http_private.h"
#include "unix-std.h"
+#include "zlib.h"
/***
* @module rspamd_http
gint fd;
gint cbref;
gint bodyref;
+ gboolean gzip;
};
static const int default_http_timeout = 5000;
static gint
lua_http_request (lua_State *L)
{
- const gchar *url, *lua_body;
- gchar *to_resolve;
- gint cbref;
- gsize bodylen;
struct event_base *ev_base;
struct rspamd_http_message *msg;
struct lua_http_cbdata *cbd;
struct rspamd_config *cfg = NULL;
struct rspamd_cryptobox_pubkey *peer_key = NULL;
struct rspamd_cryptobox_keypair *local_kp = NULL;
+ const gchar *url, *lua_body;
+ rspamd_fstring_t *body = NULL;
+ gchar *to_resolve;
+ gint cbref;
+ gsize bodylen;
gdouble timeout = default_http_timeout;
gint flags = 0;
gchar *mime_type = NULL;
gsize max_size = 0;
+ gboolean gzip = FALSE;
if (lua_gettop (L) >= 2) {
/* url, callback and event_base format */
lua_gettable (L, 1);
if (lua_type (L, -1) == LUA_TSTRING) {
lua_body = lua_tolstring (L, -1, &bodylen);
- rspamd_http_message_set_body (msg, lua_body, bodylen);
+ body = rspamd_fstring_new_init (lua_body, bodylen);
}
else if (lua_type (L, -1) == LUA_TUSERDATA) {
t = lua_check_text (L, -1);
/* TODO: think about zero-copy possibilities */
if (t) {
- rspamd_http_message_set_body (msg, t->start, t->len);
+ body = rspamd_fstring_new_init (t->start, t->len);
}
}
lua_pop (L, 1);
lua_pop (L, 1);
+ lua_pushstring (L, "gzip");
+ lua_gettable (L, 1);
+
+ if (!!lua_toboolean (L, -1)) {
+ gzip = TRUE;
+ }
+
+ lua_pop (L, 1);
+
lua_pushstring (L, "no_ssl_verify");
lua_gettable (L, 1);
cbd->host = rspamd_fstring_cstr (msg->host);
}
+ if (body) {
+ if (gzip) {
+ if (rspamd_fstring_gzip (&body)) {
+ rspamd_http_message_add_header (msg, "Content-Encoding", "gzip");
+ }
+ }
+
+ rspamd_http_message_set_body_from_fstring_steal (msg, body);
+ }
+
+ if (gzip) {
+ cbd->gzip = TRUE;
+ /* TODO: Add client support for gzip */
+ }
+
if (session) {
cbd->session = session;
rspamd_session_add_event (session,