Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 16:45 UTC
reverseproxy: HTTP 504 for upstream timeouts (#4824)
Closes #4823
Matt Holt committed
Jun 3, 2022 at 14:13 UTC
5e729c1e85f8ac9eac1e136ec0261c6e7b1c865e
1 file changed
+6
-1
modules/caddyhttp/reverseproxy/reverseproxy.go
+6
-1
@@ -524,7 +524,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h
524
525
// proxy the request to that upstream
526
proxyErr = h.reverseProxy(w, r, origReq, repl, dialInfo, next)
527
- if proxyErr == nil || proxyErr == context.Canceled {
527
+ if proxyErr == nil || errors.Is(proxyErr, context.Canceled) {
528
// context.Canceled happens when the downstream client
529
// cancels the request, which is not our failure
530
return true, nil
@@ -1180,6 +1180,11 @@ func statusError(err error) error {
1180
// errors proxying usually mean there is a problem with the upstream(s)
1181
statusCode := http.StatusBadGateway
1182
1183
+ // timeout errors have a standard status code (see issue #4823)
1184
+ if err, ok := err.(net.Error); ok && err.Timeout() {
1185
+ statusCode = http.StatusGatewayTimeout
1186
+ }
1187
+
1188
// if the client canceled the request (usually this means they closed
1189
// the connection, so they won't see any response), we can report it
1190
// as a client error (4xx) and not a server error (5xx); unfortunately