summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2022-06-03 14:13:47 -0600
committerGitHub <noreply@github.com>2022-06-03 14:13:47 -0600
commit5e729c1e85f8ac9eac1e136ec0261c6e7b1c865e (patch)
treec9cab3d31069a5b49ac4da0de551602318591c47 /modules/caddyhttp/reverseproxy
parent0a14f97e4944a1aadc5fa9e6e8569759a9f0b5ec (diff)
reverseproxy: HTTP 504 for upstream timeouts (#4824)
Closes #4823
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 07eb99c..1068c23 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -524,7 +524,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h
// proxy the request to that upstream
proxyErr = h.reverseProxy(w, r, origReq, repl, dialInfo, next)
- if proxyErr == nil || proxyErr == context.Canceled {
+ if proxyErr == nil || errors.Is(proxyErr, context.Canceled) {
// context.Canceled happens when the downstream client
// cancels the request, which is not our failure
return true, nil
@@ -1180,6 +1180,11 @@ func statusError(err error) error {
// errors proxying usually mean there is a problem with the upstream(s)
statusCode := http.StatusBadGateway
+ // timeout errors have a standard status code (see issue #4823)
+ if err, ok := err.(net.Error); ok && err.Timeout() {
+ statusCode = http.StatusGatewayTimeout
+ }
+
// if the client canceled the request (usually this means they closed
// the connection, so they won't see any response), we can report it
// as a client error (4xx) and not a server error (5xx); unfortunately