Delete errorneous empty content length header (#53843)

fixes https://github.com/vercel/next.js/issues/53822

PR https://github.com/vercel/next.js/pull/53368 introduced a regression causing fetch with custom headers to fail in safari.
There are known issues with uncidi when a content-length: 0 header exists.

When performing a custom fetch in safari, this header is present.
When performing a custom fetch in chrome, this header is not present.




Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
This commit is contained in:
Dave Carlson 2023-08-10 23:03:13 +01:00 committed by GitHub
parent 6f7ffadc86
commit 9bb10b1cb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,12 @@ export const filterReqHeaders = (
headers: Record<string, undefined | string | number | string[]>,
forbiddenHeaders: string[]
) => {
// Some browsers are not matching spec and sending Content-Length: 0. This causes issues in undici
// https://github.com/nodejs/undici/issues/2046
if (headers['content-length'] && headers['content-length'] === '0') {
delete headers['content-length']
}
for (const [key, value] of Object.entries(headers)) {
if (
forbiddenHeaders.includes(key) ||