Repository: caddyserver/caddy
File: modules/caddyhttp/reverseproxy/reverseproxy.go (Go)

Code before:

	// response is the actual response received from the proxy
	// roundtrip, to potentially be copied if a copy_response
	// handler is in the handle_response routes.
	response *http.Response

	// start is the time just before the proxy roundtrip was
	// performed, used for logging.
	start time.Time

	// logger is the prepared logger which is used to write logs
	// with the request, duration, and selected upstream attached.
	logger *zap.Logger

	// isFinalized is whether the response has been finalized,
	// i.e. copied and closed, to make sure that it doesn't
	// happen twice.
	isFinalized bool
}

// 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.
// This can be replaced with context.WithoutCancel once
// the minimum required required version of Go is 1.21.
type ignoreClientGoneContext struct {
	context.Context
}

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
// from the proxy handler.
const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context"

// Interface guards
var (
	_ caddy.Provisioner           = (*Handler)(nil)
	_ caddy.CleanerUpper          = (*Handler)(nil)

Review comment (suggestion):
```suggestion
// 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 required version of Go is 1.21.
```

A little clarifying

(Added the TODO just so we can find it easier later :upside_down_face: )

Code after:

	// response is the actual response received from the proxy
	// roundtrip, to potentially be copied if a copy_response
	// handler is in the handle_response routes.
	response *http.Response

	// start is the time just before the proxy roundtrip was
	// performed, used for logging.
	start time.Time

	// logger is the prepared logger which is used to write logs
	// with the request, duration, and selected upstream attached.
	logger *zap.Logger

	// isFinalized is whether the response has been finalized,
	// i.e. copied and closed, to make sure that it doesn't
	// happen twice.
	isFinalized bool
}

// 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.
// 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
}

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
// from the proxy handler.
const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context"