mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-28 04:45:56 +03:00
reverseproxy: Connection termination cleanup (#5663)
This commit is contained in:
parent
94749e119a
commit
da23501457
1 changed files with 19 additions and 6 deletions
|
@ -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
|
// regardless, and we should expect client disconnection in low-latency streaming
|
||||||
// scenarios (see issue #4922)
|
// scenarios (see issue #4922)
|
||||||
if h.FlushInterval == -1 {
|
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
|
// 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
|
// ignoreClientGoneContext is a special context.Context type
|
||||||
// intended for use when doing a RoundTrip where you don't
|
// intended for use when doing a RoundTrip where you don't
|
||||||
// want a client disconnection to cancel the request during
|
// want a client disconnection to cancel the request during
|
||||||
// the roundtrip. Set its done field to a Done() channel
|
// the roundtrip.
|
||||||
// of a context that doesn't get canceled when the client
|
// This context clears cancellation, error, and deadline methods,
|
||||||
// disconnects, such as caddy.Context.Done() instead.
|
// 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 {
|
type ignoreClientGoneContext struct {
|
||||||
context.Context
|
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
|
// proxyHandleResponseContextCtxKey is the context key for the active proxy handler
|
||||||
// so that handle_response routes can inherit some config options
|
// so that handle_response routes can inherit some config options
|
||||||
|
|
Loading…
Reference in a new issue