mirror of
https://mirror.skon.top/github.com/router-for-me/CLIProxyAPI
synced 2026-04-21 01:10:14 +08:00
fix(handlers): include execution session metadata and skip idempotency key when absent
- Refactored `requestExecutionMetadata` to handle empty `Idempotency-Key` gracefully. - Added test to validate metadata inclusion of execution session without idempotency key.
This commit is contained in:
@@ -194,11 +194,11 @@ func requestExecutionMetadata(ctx context.Context) map[string]any {
|
||||
key = strings.TrimSpace(ginCtx.GetHeader("Idempotency-Key"))
|
||||
}
|
||||
}
|
||||
if key == "" {
|
||||
return make(map[string]any)
|
||||
}
|
||||
|
||||
meta := map[string]any{idempotencyKeyMetadataKey: key}
|
||||
meta := make(map[string]any)
|
||||
if key != "" {
|
||||
meta[idempotencyKeyMetadataKey] = key
|
||||
}
|
||||
if pinnedAuthID := pinnedAuthIDFromContext(ctx); pinnedAuthID != "" {
|
||||
meta[coreexecutor.PinnedAuthMetadataKey] = pinnedAuthID
|
||||
}
|
||||
|
||||
20
sdk/api/handlers/handlers_metadata_test.go
Normal file
20
sdk/api/handlers/handlers_metadata_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
coreexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestRequestExecutionMetadataIncludesExecutionSessionWithoutIdempotencyKey(t *testing.T) {
|
||||
ctx := WithExecutionSessionID(context.Background(), "session-1")
|
||||
|
||||
meta := requestExecutionMetadata(ctx)
|
||||
if got := meta[coreexecutor.ExecutionSessionMetadataKey]; got != "session-1" {
|
||||
t.Fatalf("ExecutionSessionMetadataKey = %v, want %q", got, "session-1")
|
||||
}
|
||||
if _, ok := meta[idempotencyKeyMetadataKey]; ok {
|
||||
t.Fatalf("unexpected idempotency key in metadata: %v", meta[idempotencyKeyMetadataKey])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user