Skip to content
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

fix: canonicalize user defined headers #9734

Merged
merged 1 commit into from
Mar 17, 2023
Merged

fix: canonicalize user defined headers #9734

merged 1 commit into from
Mar 17, 2023

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Mar 17, 2023

@lidel I did not use .Set because that does not allow us to define multiple values, which the user can.

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key. https://pkg.go.dev/net/http#Header.Set

@@ -32,7 +32,7 @@ type redirectHandler struct {

func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for k, v := range i.headers {
w.Header()[k] = v
w.Header()[http.CanonicalHeaderKey(k)] = v

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't speak go, but https://pkg.go.dev/net/http#CanonicalHeaderKey seems to imply that this should work!

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, this is actually less code than using https://pkg.go.dev/net/http#Header.Add i had in mind initially :)

@lidel lidel merged commit ed671e8 into master Mar 17, 2023
@lidel lidel deleted the canonicalize-header branch March 17, 2023 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants