Unverified Commit 23f62354 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

add "expect" to list of forbidden IPC headers (#53947)

`expect` is an unsupported header for undici: https://github.com/nodejs/undici/blob/c83b084879fa0bb8e0469d31ec61428ac68160d5/lib/core/request.js#L354 -- this filters it out so that the API routes don't throw an internal server error if that header is included. 

Also added a test case for the previously submitted PR that was added for `content-length: 0`

- x-ref: #53843

Fixes #53822 (erroneously closed by a content-length issue being fixed)
parent 2b38118e
......@@ -6,6 +6,8 @@ export const ipcForbiddenHeaders = [
'transfer-encoding',
// https://github.com/nodejs/undici/issues/1470
'connection',
// marked as unsupported by undici: https://github.com/nodejs/undici/blob/c83b084879fa0bb8e0469d31ec61428ac68160d5/lib/core/request.js#L354
'expect',
]
export const actionsForbiddenHeaders = [
......
export async function POST(req: Request) {
return new Response('Hello, Next.js!')
}
export async function DELETE(req: Request) {
return new Response('Hello, Next.js!')
}
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'ipc-forbidden-headers',
{
files: __dirname,
},
({ next }) => {
it('should not error if expect header is included', async () => {
let res = await next.fetch('/api/pages-api', {
method: 'POST',
headers: { expect: '100-continue' },
})
let text = await res.text()
expect(text).toEqual('Hello, Next.js!')
res = await next.fetch('/api/app-api', {
method: 'POST',
headers: {
expect: '100-continue',
},
})
text = await res.text()
expect(text).toEqual('Hello, Next.js!')
expect(next.cliOutput).not.toContain('UND_ERR_NOT_SUPPORTED')
})
it("should not error on content-length: 0 if request shouldn't contain a payload", async () => {
let res = await next.fetch('/api/pages-api', {
method: 'DELETE',
headers: { 'content-length': '0' },
})
expect(res.status).toBe(200)
res = await next.fetch('/api/app-api', {
method: 'DELETE',
headers: { 'content-length': '0' },
})
expect(res.status).toBe(200)
expect(next.cliOutput).not.toContain(
'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
)
})
}
)
export default async function handler(req, res) {
return res.status(200).send('Hello, Next.js!')
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment