diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-11 12:56:44 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-11 12:56:44 +0000 |
commit | 8cb0e4aa8199af52316806f41f1a7cd1e25ceedb (patch) | |
tree | 0a5a8519ea3e5ec5be32bf72d9d9e99086aec7ab /src/libutil/http.c | |
parent | 4784b2685577df0f0e1263d024dc073e571b0328 (diff) | |
download | rspamd-8cb0e4aa8199af52316806f41f1a7cd1e25ceedb.tar.gz rspamd-8cb0e4aa8199af52316806f41f1a7cd1e25ceedb.zip |
[Minor] Allow to append headers for rspamd http router
Diffstat (limited to 'src/libutil/http.c')
-rw-r--r-- | src/libutil/http.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c index 635bfea27..df167d615 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -2946,6 +2946,7 @@ rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry, reply_msg = rspamd_http_new_message (HTTP_RESPONSE); reply_msg->date = time (NULL); reply_msg->code = 200; + rspamd_http_router_insert_headers (entry->rt, reply_msg); if (!rspamd_http_message_set_body_from_fd (reply_msg, fd)) { close (fd); @@ -3024,6 +3025,7 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn, err_msg->code = err->code; rspamd_http_message_set_body (err_msg, err->message, strlen (err->message)); + rspamd_http_router_insert_headers (router, err_msg); rspamd_http_connection_reset (entry->conn); rspamd_http_connection_write_message (entry->conn, err_msg, @@ -3070,6 +3072,7 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn, err_msg = rspamd_http_new_message (HTTP_RESPONSE); err_msg->date = time (NULL); err_msg->code = err->code; + rspamd_http_router_insert_headers (router, err_msg); rspamd_http_message_set_body (err_msg, err->message, strlen (err->message)); rspamd_http_connection_reset (entry->conn); @@ -3107,6 +3110,8 @@ rspamd_http_router_new (rspamd_http_router_error_handler_t eh, new->error_handler = eh; new->finish_handler = fh; new->ev_base = base; + new->response_headers = g_hash_table_new_full (rspamd_strcase_hash, + rspamd_strcase_equal, g_free, g_free); if (timeout) { new->tv = *timeout; @@ -3167,6 +3172,32 @@ rspamd_http_router_add_path (struct rspamd_http_connection_router *router, } void +rspamd_http_router_add_header (struct rspamd_http_connection_router *router, + const gchar *name, const gchar *value) +{ + if (name != NULL && value != NULL && router != NULL) { + g_hash_table_replace (router->response_headers, g_strdup (name), + g_strdup (value)); + } +} + +void +rspamd_http_router_insert_headers (struct rspamd_http_connection_router *router, + struct rspamd_http_message *msg) +{ + GHashTableIter it; + gpointer k, v; + + if (router && msg) { + g_hash_table_iter_init (&it, router->response_headers); + + while (g_hash_table_iter_next (&it, &k, &v)) { + rspamd_http_message_add_header (msg, k, v); + } + } +} + +void rspamd_http_router_add_regexp (struct rspamd_http_connection_router *router, struct rspamd_regexp_s *re, rspamd_http_router_handler_t handler) { @@ -3240,6 +3271,7 @@ rspamd_http_router_free (struct rspamd_http_connection_router *router) g_ptr_array_free (router->regexps, TRUE); g_hash_table_unref (router->paths); + g_hash_table_unref (router->response_headers); g_slice_free1 (sizeof (struct rspamd_http_connection_router), router); } } |