From 1576ee279f03dad56808acb6bb3e3b30b4706c31 Mon Sep 17 00:00:00 2001 From: "Malte S. Stretz" Date: Sat, 20 Nov 2021 17:39:21 +0100 Subject: [PATCH] Return 5xx when upstream is unreachable Currently a 404 is returned for a misconfigured or unavailable upstream server. Since that's a server error it should be a 5xx instead; a 404 is confusing when used as a forward proxy and might even be harmful when used as a reverse proxy. It is debatable if another 5xx code might be better; the misconfigured situation might better be a 500 whereas the connection issue could be a 503 instead (as used eg. in haproxy). --- etc/tinyproxy.conf.in | 2 +- src/reqs.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/tinyproxy.conf.in b/etc/tinyproxy.conf.in index 06f5480..ce27f7e 100644 --- a/etc/tinyproxy.conf.in +++ b/etc/tinyproxy.conf.in @@ -56,8 +56,8 @@ Timeout 600 # /usr/share/tinyproxy # /etc/tinyproxy # -#ErrorFile 404 "@pkgdatadir@/404.html" #ErrorFile 400 "@pkgdatadir@/400.html" +#ErrorFile 502 "@pkgdatadir@/502.html" #ErrorFile 503 "@pkgdatadir@/503.html" #ErrorFile 403 "@pkgdatadir@/403.html" #ErrorFile 408 "@pkgdatadir@/408.html" diff --git a/src/reqs.c b/src/reqs.c index cdc3b61..50f6914 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -1424,7 +1424,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request) log_message (LOG_WARNING, "No upstream proxy defined for %s.", request->host); - indicate_http_error (connptr, 404, + indicate_http_error (connptr, 502, "Unable to connect to upstream proxy."); return -1; } @@ -1436,7 +1436,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request) if (connptr->server_fd < 0) { log_message (LOG_WARNING, "Could not connect to upstream proxy."); - indicate_http_error (connptr, 404, + indicate_http_error (connptr, 502, "Unable to connect to upstream proxy", "detail", "A network error occurred while trying to "