Skip to content

Commit

Permalink
released v5.0.10 - fix: createResponse could pollute headers in Node …
Browse files Browse the repository at this point in the history
…still, if given request as second arg
  • Loading branch information
kwhitley committed Apr 9, 2024
1 parent 4c4f413 commit e0ecf73
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changelog

- **v5.0.10**
- fixed: response formatters in finally stage could still cross pollute headers in Node
- **v5.0.9**
- fixed: cors preflight should reflect requested headers as the default (required for credentials)
- **v5.0.7**
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.9",
"version": "5.0.10",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
Expand Down
5 changes: 1 addition & 4 deletions src/createResponse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,10 @@ describe('createResponse(mimeType: string, transform?: Function)', () => {
expect(r2).toBeUndefined()
})

it('will not apply a Request as 2nd options argument (using Request.url check method)', async () => {
it('will not apply a Request as 2nd options argument', async () => {
const request = new Request('http://foo.bar', { headers: { foo: 'bar' }})
const response = json(1, request)
// const { ...restCheck } = request

// expect(restCheck.url).toBe('http://foo.bar/')
// expect(request.url).toBe('http://foo.bar/')
expect(response.headers.get('foo')).toBe(null)
})

Expand Down
5 changes: 3 additions & 2 deletions src/createResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { ResponseFormatter } from './types'
format = 'text/plain; charset=utf-8',
transform?: (body: any) => any,
): ResponseFormatter =>
(body, { ...options } = {}) => {
(body, options = {}) => {
if (body === undefined || body instanceof Response) return body

const response = new Response(transform?.(body) ?? body, options)
// @ts-ignore
const response = new Response(transform?.(body) ?? body, options.url ? undefined : options)
response.headers.set('content-type', format)
return response
}

0 comments on commit e0ecf73

Please sign in to comment.