diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-12 12:30:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-11-12 12:30:34 +0000 |
commit | 6b49660d24022dd4637c69456f31de24264f9718 (patch) | |
tree | 06bcc2323eacd22413b4e16cd2d099436c279d4d | |
parent | 4a6835185d4e154d7b2ac026a05fbd18f1c05669 (diff) | |
download | rspamd-6b49660d24022dd4637c69456f31de24264f9718.tar.gz rspamd-6b49660d24022dd4637c69456f31de24264f9718.zip |
[Minor] Use sane HTTP codes in case of proxy errors
-rw-r--r-- | src/libutil/fstring.h | 1 | ||||
-rw-r--r-- | src/rspamd_proxy.c | 32 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index 6102215d4..730a59c1c 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -37,6 +37,7 @@ typedef struct f_str_s { #define RSPAMD_FSTRING_DATA(s) ((s)->str) #define RSPAMD_FSTRING_LEN(s) ((s)->len) +#define RSPAMD_FSTRING_LIT(lit) rspamd_fstring_new_init((lit), sizeof(lit) - 1) typedef struct f_str_tok { gsize len; diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index ae51e3e5b..e56b9b16f 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -1474,8 +1474,36 @@ proxy_client_write_error (struct rspamd_proxy_session *session, gint code, } else { reply = rspamd_http_new_message (HTTP_RESPONSE); - reply->code = code; - reply->status = rspamd_fstring_new_init (status, strlen (status)); + + switch (code) { + case ETIMEDOUT: + reply->code = 504; + reply->status = RSPAMD_FSTRING_LIT ("Gateway timeout"); + break; + case ECONNRESET: + case ECONNABORTED: + reply->code = 502; + reply->status = RSPAMD_FSTRING_LIT ("Gateway connection reset"); + break; + case ECONNREFUSED: + reply->code = 502; + reply->status = RSPAMD_FSTRING_LIT ("Gateway connection refused"); + break; + default: + if (code >= 300) { + /* Likely HTTP error */ + reply->code = code; + reply->status = rspamd_fstring_new_init (status, strlen (status)); + } + else { + reply->code = 502; + reply->status = RSPAMD_FSTRING_LIT ("Unknown gateway error: "); + reply->status = rspamd_fstring_append (reply->status, + status, strlen (status)); + } + break; + } + rspamd_http_connection_write_message (session->client_conn, reply, NULL, NULL, session, session->ctx->timeout); |