mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-20 22:51:45 +00:00
refactor(codex): align continuity helpers with review feedback
Align websocket continuity resolution with the HTTP Codex path, make auth-affinity principal keys use a stable string representation, and extract small helpers that remove duplicated continuity and affinity logic without changing the validated cache-hit behavior.
This commit is contained in:
@@ -216,13 +216,31 @@ func requestExecutionMetadata(ctx context.Context) map[string]any {
|
||||
} else if ctx != nil {
|
||||
if ginCtx, ok := ctx.Value("gin").(*gin.Context); ok && ginCtx != nil {
|
||||
if apiKey, exists := ginCtx.Get("apiKey"); exists && apiKey != nil {
|
||||
meta[authAffinityMetadataKey] = fmt.Sprintf("principal:%v", apiKey)
|
||||
if principal := stablePrincipalMetadataKey(apiKey); principal != "" {
|
||||
meta[authAffinityMetadataKey] = principal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
func stablePrincipalMetadataKey(raw any) string {
|
||||
var keyStr string
|
||||
switch v := raw.(type) {
|
||||
case string:
|
||||
keyStr = v
|
||||
case fmt.Stringer:
|
||||
keyStr = v.String()
|
||||
default:
|
||||
keyStr = fmt.Sprintf("%v", raw)
|
||||
}
|
||||
if trimmed := strings.TrimSpace(keyStr); trimmed != "" {
|
||||
return "principal:" + trimmed
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func pinnedAuthIDFromContext(ctx context.Context) string {
|
||||
if ctx == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user