-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat(httpclient): support appending the same header multiple times #830
Conversation
7067bef
to
0314907
Compare
Please sync with main and resolve CI failure and we'll review this. Thanks
|
0314907
to
f8fe86a
Compare
@marefr I've fixed the test. back to you 🏸 ! |
f8fe86a
to
c6c0ded
Compare
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.
I think that in general, it makes sense to use the same type than the upstream HTTP header: https://pkg.go.dev/net/http#Header but I am worried about the breaking change. If we do this, we should prepare at least an adapting PR for grafana/grafana.
Regarding the original issue described in #829, I wonder if a possible workaround would be to define the multiple headers as a comma-separated list. @sathieu would that work?
backend/http_settings.go
Outdated
@@ -16,7 +16,7 @@ type HTTPSettings struct { | |||
BasicAuthEnabled bool | |||
BasicAuthUser string | |||
BasicAuthPassword string | |||
Headers map[string]string | |||
Headers map[string][]string |
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.
I would just go ahead and define this as a http.Header
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.
Good idea @andresmgot.
I have done that, and renamed from Headers
to Header
, as I broke API anyway (and this is now same as net/http
.
c6c0ded
to
bbc71f5
Compare
Thanks for your review @andresmgot.
I prepared a PR in grafana at grafana/grafana#79543.
Unfortunately, comma-separated header doesn't work for Back to you! |
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.
Thanks, one minor comment here
bbc71f5
to
3dee90d
Compare
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.
LGTM, any other thought @marefr ?
@andresmgot @marefr is there anything blocking this PR from merging? |
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.
LGTM, but a question before merging
@@ -273,7 +274,7 @@ func parseHTTPSettings(jsonData json.RawMessage, secureJSONData map[string]strin | |||
|
|||
if key, exists := dat[headerNameSuffix]; exists { | |||
if value, exists := secureJSONData[headerValueSuffix]; exists { | |||
s.Headers[key.(string)] = value | |||
s.Header.Add(key.(string), 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.
Don't understand why key needs to be cast to a string - isn't it already a string since dat
is map[string]interface{}
?
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.
dat
is map[string]interface{}
, so key := dat[headerNameSuffix]
is interface{}
.
On the other side secureJSONData
is map[string]string
, so value
doesn't need cast.
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.
Oh yeah I see that now 👍
@sathieu please sync with main branch to resolve conflicts and see my comment. Thanks |
3dee90d
to
5a057a4
Compare
@marefr I've rebased and resolved conflicts. Casting is needed. Back to you 🏓 |
hi @sathieu, there are some other files that need an update: https://drone.grafana.net/grafana/grafana-plugin-sdk-go/1981/1/3 Also, can you re-open / refresh grafana/grafana#79543? (sorry, it got closed due to inactivity) |
@sathieu back to you. Not sure whether we really should remove
|
5a057a4
to
d132ddf
Compare
Fixed, rebased and pushed.
I can't reopen. I've created a new PR: grafana/grafana#84193 |
I think |
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.
LGTM sure let's use Header
What this PR does / why we need it:
See #829
Which issue(s) this PR fixes:
Fixes #829
Special notes for your reviewer: