New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce interface to ease forward/access HTTP headers #562
Conversation
backend/data.go
Outdated
req.Headers = map[string]string{} | ||
} | ||
|
||
req.Headers[fmt.Sprintf("http_%s", key)] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason to this would be to allow the environment info to hold other things than HTTP headers.
Main goal being to not always forward all environment info in outgoing HTTP headers.
Not sure it make sense 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, I really like this idea 👏 👏 👏 👏
I have left some comments/questions:
refactor a bit, adds tests, adds proper documentation of methods and fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing 🥇
LGTM! 🚀 🚀 🚀
In grafana/grafana#58132 we're type switching on different backend request types, see code.
Introduce a new interface
ForwardHTTPHeaders
would allow us to typeswitch/typecast to that interface instead and simplify the code.From plugin authors perspective we have documentation for Forward OAuth identity for the logged-in user, Forward cookies for the logged-in user and soon for Forward user header and we provides instruction for accessing these forwarded headers by access the
request.Headers
field. This field is different for different request types:QueryDataRequest
andCheckHealthRequest
there's amap[string]string
(they're suppose to hold environment context/metadataCallResourceRequest
there's amap[string][]string
(suppose to hold HTTP headers since it's HTTP proxy over gRPC basically.With these changes, rather than accessing
request.Headers
directly to access HTTP headers it's suggested that they userequest.GetHTTPHeader(<key>)
instead, e.g.request.GetHTTPHeader(backend.OAuthIdentityTokenHeaderName)
orrequest.GetHTTPHeader(backend.OAuthIdentityIDTokenHeaderName)
, to access Forwarded OAuth Identity headers.Using
request.GetHTTPHeader(<key>)
or ``request.GetHTTPHeaders()` would also automatically handle canonical/non-canonical form problems, i.e. grafana/grafana#58598A potential alternative could be to send forwarded HTTP headers via gRPC metadata, but not sure if that can affect the gRPC connection since it uses HTTP2.
WDYT?`