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).
This commit is contained in:
Malte S. Stretz 2021-11-20 17:39:21 +01:00 committed by rofl0r
parent eced6822f8
commit 1576ee279f
2 changed files with 3 additions and 3 deletions

View File

@ -56,8 +56,8 @@ Timeout 600
# /usr/share/tinyproxy # /usr/share/tinyproxy
# /etc/tinyproxy # /etc/tinyproxy
# #
#ErrorFile 404 "@pkgdatadir@/404.html"
#ErrorFile 400 "@pkgdatadir@/400.html" #ErrorFile 400 "@pkgdatadir@/400.html"
#ErrorFile 502 "@pkgdatadir@/502.html"
#ErrorFile 503 "@pkgdatadir@/503.html" #ErrorFile 503 "@pkgdatadir@/503.html"
#ErrorFile 403 "@pkgdatadir@/403.html" #ErrorFile 403 "@pkgdatadir@/403.html"
#ErrorFile 408 "@pkgdatadir@/408.html" #ErrorFile 408 "@pkgdatadir@/408.html"

View File

@ -1424,7 +1424,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
log_message (LOG_WARNING, log_message (LOG_WARNING,
"No upstream proxy defined for %s.", "No upstream proxy defined for %s.",
request->host); request->host);
indicate_http_error (connptr, 404, indicate_http_error (connptr, 502,
"Unable to connect to upstream proxy."); "Unable to connect to upstream proxy.");
return -1; return -1;
} }
@ -1436,7 +1436,7 @@ connect_to_upstream (struct conn_s *connptr, struct request_s *request)
if (connptr->server_fd < 0) { if (connptr->server_fd < 0) {
log_message (LOG_WARNING, log_message (LOG_WARNING,
"Could not connect to upstream proxy."); "Could not connect to upstream proxy.");
indicate_http_error (connptr, 404, indicate_http_error (connptr, 502,
"Unable to connect to upstream proxy", "Unable to connect to upstream proxy",
"detail", "detail",
"A network error occurred while trying to " "A network error occurred while trying to "