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 Access-Control-Request-Headers parsing issue for AWS API Gateway #141

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,12 @@ func (c *Cors) handlePreflight(w http.ResponseWriter, r *http.Request) {
c.logf(" Preflight aborted: method '%s' not allowed", reqMethod)
return
}
reqHeaders := parseHeaderList(r.Header.Get("Access-Control-Request-Headers"))
// Amazon API Gateway is sometimes feeding multiple values for
// Access-Control-Request-Headers in a way where r.Header.Values() picks
// them all up, but r.Header.Get() does not.
// I suspect it is something like this: https://stackoverflow.com/a/4371395
reqHeaderList := strings.Join(r.Header.Values("Access-Control-Request-Headers"), ",")
reqHeaders := parseHeaderList(reqHeaderList)
if !c.areHeadersAllowed(reqHeaders) {
c.logf(" Preflight aborted: headers '%v' not allowed", reqHeaders)
return
Expand Down