]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Treat special HTTP methods specially
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Jan 2017 13:40:33 +0000 (13:40 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 11 Jan 2017 13:40:33 +0000 (13:40 +0000)
interface/js/rspamd.js
src/libutil/http.c
src/libutil/http.h

index c414ccbf1971eb3f6b10a69549ceaf88393b1876..41fc43986be7ac5c82071abade5d2f6f1e5ec957 100644 (file)
                                     on_error(neighbours_status[ind],
                                             jqXHR, textStatus, errorThrown);
                                 }
+                                if (neighbours_status.every(function (elt) {return elt.checked;})) {
+                                    on_success(neighbours_status);
+                                }
                             }
                             //error display
                         });
index df167d61528e1084e6e8c5bd5217b9d8978adf7d..deed78a1a89cfff84e4a349d6649c3c86709d0cf 100644 (file)
@@ -2965,6 +2965,32 @@ rspamd_http_router_try_file (struct rspamd_http_connection_entry *entry,
        return TRUE;
 }
 
+static void
+rspamd_http_router_send_error (GError *err,
+               struct rspamd_http_connection_entry *entry)
+{
+       struct rspamd_http_message *err_msg;
+
+       err_msg = rspamd_http_new_message (HTTP_RESPONSE);
+       err_msg->date = time (NULL);
+       err_msg->code = err->code;
+       rspamd_http_message_set_body (err_msg, err->message,
+                       strlen (err->message));
+       entry->is_reply = TRUE;
+       err_msg->status = rspamd_fstring_new_init (err->message, strlen (err->message));
+       rspamd_http_router_insert_headers (entry->rt, err_msg);
+       rspamd_http_connection_reset (entry->conn);
+       rspamd_http_connection_write_message (entry->conn,
+                       err_msg,
+                       NULL,
+                       "text/plain",
+                       entry,
+                       entry->conn->fd,
+                       entry->rt->ptv,
+                       entry->rt->ev_base);
+}
+
+
 static int
 rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
        struct rspamd_http_message *msg)
@@ -2972,7 +2998,7 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
        struct rspamd_http_connection_entry *entry = conn->ud;
        rspamd_http_router_handler_t handler = NULL;
        gpointer found;
-       struct rspamd_http_message *err_msg;
+
        GError *err;
        rspamd_ftok_t lookup;
        struct http_parser_url u;
@@ -2991,6 +3017,24 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                rspamd_http_entry_free (entry);
        }
        else {
+               if (G_UNLIKELY (msg->method != HTTP_GET && msg->method != HTTP_POST)) {
+                       if (router->unknown_method_handler) {
+                               return router->unknown_method_handler (entry, msg);
+                       }
+                       else {
+                               err = g_error_new (HTTP_ERROR, 500,
+                                               "Invalid method");
+                               if (entry->rt->error_handler != NULL) {
+                                       entry->rt->error_handler (entry, err);
+                               }
+
+                               rspamd_http_router_send_error (err, entry);
+                               g_error_free (err);
+
+                               return 0;
+                       }
+               }
+
                /* Search for path */
                if (msg->url != NULL && msg->url->len != 0) {
 
@@ -3020,21 +3064,7 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                                entry->rt->error_handler (entry, err);
                        }
 
-                       err_msg = rspamd_http_new_message (HTTP_RESPONSE);
-                       err_msg->date = time (NULL);
-                       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,
-                                       NULL,
-                                       "text/plain",
-                                       entry,
-                                       entry->conn->fd,
-                                       entry->rt->ptv,
-                                       entry->rt->ev_base);
+                       rspamd_http_router_send_error (err, entry);
                        g_error_free (err);
 
                        return 0;
@@ -3069,21 +3099,7 @@ rspamd_http_router_finish_handler (struct rspamd_http_connection *conn,
                                }
 
                                msg_info ("path: %T not found", &lookup);
-                               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);
-                               rspamd_http_connection_write_message (entry->conn,
-                                       err_msg,
-                                       NULL,
-                                       "text/plain",
-                                       entry,
-                                       entry->conn->fd,
-                                       entry->rt->ptv,
-                                       entry->rt->ev_base);
+                               rspamd_http_router_send_error (err, entry);
                                g_error_free (err);
                        }
                }
index f41c3ee31ad3a8fcf93eabad46bc9fac2de4dd8f..3bad64ae2d137367867b32b4fc686b8e38f5b295 100644 (file)
@@ -134,6 +134,7 @@ struct rspamd_http_connection_router {
        struct event_base *ev_base;
        struct rspamd_keypair_cache *cache;
        gchar *default_fs_path;
+       rspamd_http_router_handler_t unknown_method_handler;
        struct rspamd_cryptobox_keypair *key;
        rspamd_http_router_error_handler_t error_handler;
        rspamd_http_router_finish_handler_t finish_handler;