mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
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
26 lines
878 B
Go
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
|
|
}
|