Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 17:00 UTC
reverseproxy: use context.WithoutCancel (#6116)
WeidiDeng committed
Feb 20, 2024 at 11:25 UTC
53f7035299a6de0553349e3b5bcabcf422f07b94
1 file changed
+1
-27
modules/caddyhttp/reverseproxy/reverseproxy.go
+1
-27
@@ -783,7 +783,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, origRe
783
// regardless, and we should expect client disconnection in low-latency streaming
784
// scenarios (see issue #4922)
785
if h.FlushInterval == -1 {
786
- req = req.WithContext(ignoreClientGoneContext{req.Context()})
786
+ req = req.WithContext(context.WithoutCancel(req.Context()))
787
}
788
789
// do the round-trip; emit debug log with values we know are
@@ -1419,32 +1419,6 @@ type handleResponseContext struct {
1419
isFinalized bool
1420
}
1421
1422
-// ignoreClientGoneContext is a special context.Context type
1423
-// intended for use when doing a RoundTrip where you don't
1424
-// want a client disconnection to cancel the request during
1425
-// the roundtrip.
1426
-// This context clears cancellation, error, and deadline methods,
1427
-// but still allows values to pass through from its embedded
1428
-// context.
1429
-//
1430
-// TODO: This can be replaced with context.WithoutCancel once
1431
-// the minimum required version of Go is 1.21.
1432
-type ignoreClientGoneContext struct {
1433
- context.Context
1434
-}
1435
-
1436
-func (c ignoreClientGoneContext) Deadline() (deadline time.Time, ok bool) {
1437
- return
1438
-}
1439
-
1440
-func (c ignoreClientGoneContext) Done() <-chan struct{} {
1441
- return nil
1442
-}
1443
-
1444
-func (c ignoreClientGoneContext) Err() error {
1445
- return nil
1446
-}
1447
-
1422
// proxyHandleResponseContextCtxKey is the context key for the active proxy handler
1423
// so that handle_response routes can inherit some config options
1424
// from the proxy handler.