Skip to content

Commit 74f63ab

Browse files
committed
released v5.0.17 - fixes #242 - corsify should clone response
1 parent 9bfedb0 commit 74f63ab

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## Changelog
2+
#### v5.0.17
3+
- fixed: corsify should clone response before appending headers
24
#### v5.0.16
35
- maintenance: README
46
#### v5.0.15

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "itty-router",
3-
"version": "5.0.16",
3+
"version": "5.0.17",
44
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
55
"main": "./index.js",
66
"module": "./index.mjs",

src/cors.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ describe('cors(options?: CorsOptions)', () => {
275275
expect(afterCorsify.headers.get('access-control-allow-origin')).toBeNull()
276276
expect(afterCorsify.status).toBe(101)
277277
})
278+
279+
it('clones the response', async () => {
280+
const { corsify } = cors()
281+
const originalResponse = new Response(null)
282+
const corsified = corsify(originalResponse)
283+
expect(originalResponse).not.toBe(corsified)
284+
})
278285
})
279286
})
280287
})

src/cors.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ export const cors = (options: CorsOptions = {}) => {
7878
|| response.status == 101
7979
) return response
8080

81-
// clone the response
82-
// response = response.clone()
83-
84-
return appendHeadersAndReturn(response, {
81+
return appendHeadersAndReturn(response.clone(), {
8582
'access-control-allow-origin': getAccessControlOrigin(request),
8683
'access-control-allow-credentials': credentials,
8784
})

0 commit comments

Comments
 (0)