rspamd_inet_addr_t *addr;
gchar *mime_type;
gchar *host;
+ gchar *auth;
const gchar *url;
gsize max_size;
gint flags;
gint fd;
gint cbref;
- gint bodyref;
- gboolean gzip;
};
static const int default_http_timeout = 5000;
g_free (cbd->host);
}
+ if (cbd->auth) {
+ g_free (cbd->auth);
+ }
+
if (cbd->local_kp) {
rspamd_keypair_unref (cbd->local_kp);
}
rspamd_http_connection_set_max_size (cbd->conn, cbd->max_size);
}
+ if (cbd->auth) {
+ rspamd_http_message_add_header (cbd->msg, "Authorization",
+ cbd->auth);
+ }
+
rspamd_http_connection_write_message (cbd->conn, cbd->msg,
cbd->host, cbd->mime_type, cbd, fd,
&cbd->tv, cbd->ev_base);
gdouble timeout = default_http_timeout;
gint flags = 0;
gchar *mime_type = NULL;
+ gchar *auth = NULL;
gsize max_size = 0;
gboolean gzip = FALSE;
}
lua_pop (L, 1);
+
+ lua_pushstring (L, "user");
+ lua_gettable (L, 1);
+
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ const gchar *user = lua_tostring (L, -1);
+
+ lua_pushstring (L, "password");
+ lua_gettable (L, 1);
+
+ if (lua_type (L, -1) == LUA_TSTRING) {
+ const gchar *password = lua_tostring (L, -1);
+ gchar *tmpbuf;
+ gsize tlen;
+
+ tlen = strlen (user) + strlen (password) + 1;
+ tmpbuf = g_malloc (tlen + 1);
+ rspamd_snprintf (tmpbuf, tlen + 1, "%s:%s", user, password);
+ tlen *= 2;
+ tlen += sizeof ("Basic ") - 1;
+ auth = g_malloc (tlen + 1);
+ rspamd_snprintf (auth, tlen + 1, "Basic %Bs", tmpbuf);
+ g_free (tmpbuf);
+ }
+ else {
+ msg_warn ("HTTP user must have password, disabling auth");
+ }
+
+ lua_pop (L, 1); /* password */
+ }
+
+ lua_pop (L, 1); /* username */
}
else {
msg_err ("http request has bad params");
cbd->flags = flags;
cbd->max_size = max_size;
cbd->url = url;
+ cbd->auth = auth;
if (msg->host) {
cbd->host = rspamd_fstring_cstr (msg->host);
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,