Skip to content

Commit a814d79

Browse files
authored
Re-add support for multiple Access-Control-Request-Headers field (fixes #184) (#186)
1 parent 1562b17 commit a814d79

File tree

5 files changed

+562
-303
lines changed

5 files changed

+562
-303
lines changed

cors.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,11 @@ func (c *Cors) handlePreflight(w http.ResponseWriter, r *http.Request) {
364364
// Note: the Fetch standard guarantees that at most one
365365
// Access-Control-Request-Headers header is present in the preflight request;
366366
// see step 5.2 in https://fetch.spec.whatwg.org/#cors-preflight-fetch-0.
367-
reqHeaders, found := first(r.Header, "Access-Control-Request-Headers")
368-
if found && !c.allowedHeadersAll && !c.allowedHeaders.Subsumes(reqHeaders[0]) {
369-
c.logf(" Preflight aborted: headers '%v' not allowed", reqHeaders[0])
367+
// However, some gateways split that header into multiple headers of the same name;
368+
// see https://github.com/rs/cors/issues/184.
369+
reqHeaders, found := r.Header["Access-Control-Request-Headers"]
370+
if found && !c.allowedHeadersAll && !c.allowedHeaders.Accepts(reqHeaders) {
371+
c.logf(" Preflight aborted: headers '%v' not allowed", reqHeaders)
370372
return
371373
}
372374
if c.allowedOriginsAll {

0 commit comments

Comments
 (0)