Files
Martin DisibioandGitHub 8ba3471fe6 Fix Grpc streaming handling of Authorization header (#4419)
* Grpc streaming apis preserve some headers when sending jobs to the queriers

* changelog
2024-12-06 15:12:01 -05:00

32 lines
452 B
Go

package frontend
import (
"context"
"net/http"
"google.golang.org/grpc/metadata"
)
var copyHeaders = []string{
"Authorization",
"X-Scope-OrgID",
}
func headersFromGrpcContext(ctx context.Context) (hs http.Header) {
hs = http.Header{}
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
// Tests may not have metadata so skip
return
}
for _, h := range copyHeaders {
if v := md.Get(h); len(v) > 0 {
hs[h] = v
}
}
return
}