Skip to content

Commit

Permalink
Fix Access-Control-Request-Headers parsing issue for AWS API Gateway (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cblackcom committed Mar 1, 2023
1 parent 0c96d38 commit 5c2b877
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cors.go
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

0 comments on commit 5c2b877

Please sign in to comment.