fix: forward HTTP headers to executor Options so session affinity can read X-Amp-Thread-Id
This commit is contained in:
@@ -211,6 +211,19 @@ func requestExecutionMetadata(ctx context.Context) map[string]any {
|
|||||||
return meta
|
return meta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// headersFromContext extracts the original HTTP request headers from the gin context
|
||||||
|
// embedded in the provided context. This allows session affinity selectors to read
|
||||||
|
// client headers like X-Amp-Thread-Id.
|
||||||
|
func headersFromContext(ctx context.Context) http.Header {
|
||||||
|
if ctx == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if ginCtx, ok := ctx.Value("gin").(*gin.Context); ok && ginCtx != nil && ginCtx.Request != nil {
|
||||||
|
return ginCtx.Request.Header.Clone()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func pinnedAuthIDFromContext(ctx context.Context) string {
|
func pinnedAuthIDFromContext(ctx context.Context) string {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return ""
|
return ""
|
||||||
@@ -488,6 +501,7 @@ func (h *BaseAPIHandler) ExecuteWithAuthManager(ctx context.Context, handlerType
|
|||||||
Alt: alt,
|
Alt: alt,
|
||||||
OriginalRequest: rawJSON,
|
OriginalRequest: rawJSON,
|
||||||
SourceFormat: sdktranslator.FromString(handlerType),
|
SourceFormat: sdktranslator.FromString(handlerType),
|
||||||
|
Headers: headersFromContext(ctx),
|
||||||
}
|
}
|
||||||
opts.Metadata = reqMeta
|
opts.Metadata = reqMeta
|
||||||
resp, err := h.AuthManager.Execute(ctx, providers, req, opts)
|
resp, err := h.AuthManager.Execute(ctx, providers, req, opts)
|
||||||
@@ -535,6 +549,7 @@ func (h *BaseAPIHandler) ExecuteCountWithAuthManager(ctx context.Context, handle
|
|||||||
Alt: alt,
|
Alt: alt,
|
||||||
OriginalRequest: rawJSON,
|
OriginalRequest: rawJSON,
|
||||||
SourceFormat: sdktranslator.FromString(handlerType),
|
SourceFormat: sdktranslator.FromString(handlerType),
|
||||||
|
Headers: headersFromContext(ctx),
|
||||||
}
|
}
|
||||||
opts.Metadata = reqMeta
|
opts.Metadata = reqMeta
|
||||||
resp, err := h.AuthManager.ExecuteCount(ctx, providers, req, opts)
|
resp, err := h.AuthManager.ExecuteCount(ctx, providers, req, opts)
|
||||||
@@ -586,6 +601,7 @@ func (h *BaseAPIHandler) ExecuteStreamWithAuthManager(ctx context.Context, handl
|
|||||||
Alt: alt,
|
Alt: alt,
|
||||||
OriginalRequest: rawJSON,
|
OriginalRequest: rawJSON,
|
||||||
SourceFormat: sdktranslator.FromString(handlerType),
|
SourceFormat: sdktranslator.FromString(handlerType),
|
||||||
|
Headers: headersFromContext(ctx),
|
||||||
}
|
}
|
||||||
opts.Metadata = reqMeta
|
opts.Metadata = reqMeta
|
||||||
streamResult, err := h.AuthManager.ExecuteStream(ctx, providers, req, opts)
|
streamResult, err := h.AuthManager.ExecuteStream(ctx, providers, req, opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user