mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-10-25 09:03:17 +08:00
- Add context helpers to manage execution-scoped proxy overrides - Prioritize request proxy over credential and global proxy settings across HTTP and uTLS clients - Propagate request proxy in conductor execution and plugin host adapters - Isolate Codex WebSocket connection reuse by proxy endpoint Closes: #6013
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package executor
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
type requestProxyContextKey struct{}
|
|
|
|
// WithRequestProxyURL replaces the execution-scoped proxy override.
|
|
// An empty proxy clears any override inherited from the parent context.
|
|
func WithRequestProxyURL(ctx context.Context, proxyURL string) context.Context {
|
|
proxyURL = strings.TrimSpace(proxyURL)
|
|
if ctx == nil {
|
|
ctx = context.Background()
|
|
}
|
|
return context.WithValue(ctx, requestProxyContextKey{}, proxyURL)
|
|
}
|
|
|
|
// WithoutRequestProxyURL removes an execution-scoped proxy override.
|
|
// Credential refresh uses this so token exchange keeps the account or global proxy.
|
|
func WithoutRequestProxyURL(ctx context.Context) context.Context {
|
|
if ctx == nil {
|
|
return context.Background()
|
|
}
|
|
return context.WithValue(ctx, requestProxyContextKey{}, "")
|
|
}
|
|
|
|
// RequestProxyURL returns the execution-scoped proxy override, or empty when unset.
|
|
func RequestProxyURL(ctx context.Context) string {
|
|
if ctx == nil {
|
|
return ""
|
|
}
|
|
proxyURL, _ := ctx.Value(requestProxyContextKey{}).(string)
|
|
return strings.TrimSpace(proxyURL)
|
|
}
|