Skip to content

Commit

Permalink
fix: CORS headers (#59)
Browse files Browse the repository at this point in the history
* Vary may be set already by handlers, so use append instead
* Added `HEAD` to allowed methods
* Removed `Content-Length` from expose headers as it is superfluous - it
is on the [CORS response header
safelist](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header)
* Added `Content-Range` to expose headers since we now support range
requests
  • Loading branch information
Alan Shaw authored May 15, 2024
1 parent 3603497 commit 1726f8b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ export function withCorsHeaders (handler) {
const origin = request.headers.get('origin')
if (origin) {
response.headers.set('Access-Control-Allow-Origin', origin)
response.headers.set('Vary', 'Origin')
response.headers.append('Vary', 'Origin')
} else {
response.headers.set('Access-Control-Allow-Origin', '*')
}
response.headers.set('Access-Control-Allow-Methods', 'GET')
// response.headers.append('Access-Control-Allow-Headers', 'Range')
// response.headers.append('Access-Control-Allow-Headers', 'Content-Range')
response.headers.append('Access-Control-Expose-Headers', 'Content-Length')
// response.headers.append('Access-Control-Expose-Headers', 'Content-Range')
response.headers.set('Access-Control-Allow-Methods', 'GET, HEAD')
response.headers.append('Access-Control-Expose-Headers', 'Content-Range')
return response
}
}
Expand Down

0 comments on commit 1726f8b

Please sign in to comment.