Files
CLIProxyAPI/internal/logging/request_capture.go
Dylan 4cb98e3ccd fix(logging): prevent deferred request retention on Responses WebSockets
Keep the error-only upstream request capture policy on the connection
context, before model routing and upstream execution begin. Check it before
accessing pooled Gin state so delayed plugin callbacks retain the policy
even after cancellation or Gin context reuse.

Preserve ordinary HTTP error capture, failed upgrade handling, and full
request logging. Cover large repeated requests, late callbacks, real
WebSocket logging, and Codex duplex routing with regression tests.

Related: #6960
2026-10-29 23:25:54 +08:00

26 lines
878 B
Go

package logging
import "context"
type deferredAPIRequestCaptureDisabledKey struct{}
// WithDeferredAPIRequestCaptureDisabled skips error-only upstream request capture
// for this context and its descendants. Full request logging is unaffected.
// Connection-scoped contexts keep this policy even when asynchronous callbacks
// outlive the handler and its pooled Gin context is reused.
func WithDeferredAPIRequestCaptureDisabled(ctx context.Context) context.Context {
if ctx == nil {
ctx = context.Background()
}
return context.WithValue(ctx, deferredAPIRequestCaptureDisabledKey{}, true)
}
// DeferredAPIRequestCaptureDisabled reports whether error-only capture is disabled.
func DeferredAPIRequestCaptureDisabled(ctx context.Context) bool {
if ctx == nil {
return false
}
disabled, _ := ctx.Value(deferredAPIRequestCaptureDisabledKey{}).(bool)
return disabled
}