@@ -211,6 +211,19 @@ func requestExecutionMetadata(ctx context.Context) map[string]any {
211211 return meta
212212}
213213
214+ // headersFromContext extracts the original HTTP request headers from the gin context
215+ // embedded in the provided context. This allows session affinity selectors to read
216+ // client headers like X-Amp-Thread-Id.
217+ func headersFromContext (ctx context.Context ) http.Header {
218+ if ctx == nil {
219+ return nil
220+ }
221+ if ginCtx , ok := ctx .Value ("gin" ).(* gin.Context ); ok && ginCtx != nil && ginCtx .Request != nil {
222+ return ginCtx .Request .Header .Clone ()
223+ }
224+ return nil
225+ }
226+
214227func pinnedAuthIDFromContext (ctx context.Context ) string {
215228 if ctx == nil {
216229 return ""
@@ -488,6 +501,7 @@ func (h *BaseAPIHandler) ExecuteWithAuthManager(ctx context.Context, handlerType
488501 Alt : alt ,
489502 OriginalRequest : rawJSON ,
490503 SourceFormat : sdktranslator .FromString (handlerType ),
504+ Headers : headersFromContext (ctx ),
491505 }
492506 opts .Metadata = reqMeta
493507 resp , err := h .AuthManager .Execute (ctx , providers , req , opts )
@@ -535,6 +549,7 @@ func (h *BaseAPIHandler) ExecuteCountWithAuthManager(ctx context.Context, handle
535549 Alt : alt ,
536550 OriginalRequest : rawJSON ,
537551 SourceFormat : sdktranslator .FromString (handlerType ),
552+ Headers : headersFromContext (ctx ),
538553 }
539554 opts .Metadata = reqMeta
540555 resp , err := h .AuthManager .ExecuteCount (ctx , providers , req , opts )
@@ -586,6 +601,7 @@ func (h *BaseAPIHandler) ExecuteStreamWithAuthManager(ctx context.Context, handl
586601 Alt : alt ,
587602 OriginalRequest : rawJSON ,
588603 SourceFormat : sdktranslator .FromString (handlerType ),
604+ Headers : headersFromContext (ctx ),
589605 }
590606 opts .Metadata = reqMeta
591607 streamResult , err := h .AuthManager .ExecuteStream (ctx , providers , req , opts )
0 commit comments