summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authormmm444 <michal.rydlo@gmail.com>2023-08-01 16:01:12 +0200
committerGitHub <noreply@github.com>2023-08-01 14:01:12 +0000
commitda23501457e90024814fe0149aaa57dd4384227a (patch)
tree47bb3444e5dc704eaa89c544fd46ce88e106a962 /modules/caddyhttp
parent94749e119a9dcfe9658e603753b18ae92f348aad (diff)
reverseproxy: Connection termination cleanup (#5663)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index d1c9352..b331c6b 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -769,7 +769,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, origRe
// regardless, and we should expect client disconnection in low-latency streaming
// scenarios (see issue #4922)
if h.FlushInterval == -1 {
- req = req.WithContext(ignoreClientGoneContext{req.Context(), h.ctx.Done()})
+ req = req.WithContext(ignoreClientGoneContext{req.Context()})
}
// do the round-trip; emit debug log with values we know are
@@ -1398,15 +1398,28 @@ type handleResponseContext struct {
// ignoreClientGoneContext is a special context.Context type
// intended for use when doing a RoundTrip where you don't
// want a client disconnection to cancel the request during
-// the roundtrip. Set its done field to a Done() channel
-// of a context that doesn't get canceled when the client
-// disconnects, such as caddy.Context.Done() instead.
+// the roundtrip.
+// This context clears cancellation, error, and deadline methods,
+// but still allows values to pass through from its embedded
+// context.
+//
+// TODO: This can be replaced with context.WithoutCancel once
+// the minimum required version of Go is 1.21.
type ignoreClientGoneContext struct {
context.Context
- done <-chan struct{}
}
-func (c ignoreClientGoneContext) Done() <-chan struct{} { return c.done }
+func (c ignoreClientGoneContext) Deadline() (deadline time.Time, ok bool) {
+ return
+}
+
+func (c ignoreClientGoneContext) Done() <-chan struct{} {
+ return nil
+}
+
+func (c ignoreClientGoneContext) Err() error {
+ return nil
+}
// proxyHandleResponseContextCtxKey is the context key for the active proxy handler
// so that handle_response routes can inherit some config options