Skip to content

Commit

Permalink
released v5.0.17 - fixes #242 - corsify should clone response
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Apr 28, 2024
1 parent 9bfedb0 commit 74f63ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Changelog
#### v5.0.17
- fixed: corsify should clone response before appending headers
#### v5.0.16
- maintenance: README
#### v5.0.15
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itty-router",
"version": "5.0.16",
"version": "5.0.17",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
Expand Down
7 changes: 7 additions & 0 deletions src/cors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ describe('cors(options?: CorsOptions)', () => {
expect(afterCorsify.headers.get('access-control-allow-origin')).toBeNull()
expect(afterCorsify.status).toBe(101)
})

it('clones the response', async () => {
const { corsify } = cors()
const originalResponse = new Response(null)
const corsified = corsify(originalResponse)
expect(originalResponse).not.toBe(corsified)
})
})
})
})
5 changes: 1 addition & 4 deletions src/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ export const cors = (options: CorsOptions = {}) => {
|| response.status == 101
) return response

// clone the response
// response = response.clone()

return appendHeadersAndReturn(response, {
return appendHeadersAndReturn(response.clone(), {
'access-control-allow-origin': getAccessControlOrigin(request),
'access-control-allow-credentials': credentials,
})
Expand Down

0 comments on commit 74f63ab

Please sign in to comment.