From 647adeec7fedbac5c39731a67f2b284b2d93090c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 20 Nov 2018 16:59:21 +0000 Subject: [Minor] Improve encryption requirement error code --- src/libutil/http.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libutil/http.c') diff --git a/src/libutil/http.c b/src/libutil/http.c index bc4fc5283..a82fc24f7 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -45,6 +45,7 @@ enum rspamd_http_priv_flags { RSPAMD_HTTP_CONN_FLAG_NEW_HEADER = 1 << 1, RSPAMD_HTTP_CONN_FLAG_RESETED = 1 << 2, RSPAMD_HTTP_CONN_FLAG_TOO_LARGE = 1 << 3, + RSPAMD_HTTP_CONN_FLAG_ENCRYPTION_NEEDED = 1 << 4, }; #define IS_CONN_ENCRYPTED(c) ((c)->flags & RSPAMD_HTTP_CONN_FLAG_ENCRYPTED) @@ -915,6 +916,7 @@ rspamd_http_on_message_complete (http_parser * parser) priv = conn->priv; if ((conn->opts & RSPAMD_HTTP_REQUIRE_ENCRYPTION) && !IS_CONN_ENCRYPTED (priv)) { + priv->flags |= RSPAMD_HTTP_CONN_FLAG_ENCRYPTION_NEEDED; msg_err ("unencrypted connection when encryption has been requested"); return -1; } @@ -1185,8 +1187,12 @@ rspamd_http_event_handler (int fd, short what, gpointer ud) "Request entity too large: %zu", (size_t)priv->parser.content_length); } + else if (priv->flags & RSPAMD_HTTP_CONN_FLAG_ENCRYPTION_NEEDED) { + err = g_error_new (HTTP_ERROR, 400, + "Encryption required"); + } else { - err = g_error_new (HTTP_ERROR, priv->parser.http_errno, + err = g_error_new (HTTP_ERROR, 500 + priv->parser.http_errno, "HTTP parser error: %s", http_errno_description (priv->parser.http_errno)); } -- cgit v1.2.3