-
Notifications
You must be signed in to change notification settings - Fork 29k
Closed as not planned
Labels
RuntimeRelated to Node.js or Edge Runtime with Next.js.Related to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.Issue was opened via the bug report template.lockedstaleThe issue has not seen recent activity.The issue has not seen recent activity.
Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Home
Binaries:
Node: 20.5.1
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 13.4.14-canary.1
eslint-config-next: 13.4.13
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.6
Next.js Config:
output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime)
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/agitated-yonath-cy9nps
To Reproduce
- Start the server provided in the codesandbox demo
- Open a new terminal and run any of the following:
curl localhost:3000/example -X GET -H "Content-Type: text/plain" -d "Test"
curl localhost:3000/example -X GET -H "Content-Type: text/plain" -d ""
curl localhost:3000/example -X DELETE -H "Content-Type: text/plain" -d ""
- Observe curl output as: Internal Server Error. Observe exception in server.
Describe the Bug
Sending a request to an API route with a body and without the POST method causes an internal server error.
Exception:
TypeError: fetch failed
at Object.fetch (/project/sandbox/node_modules/next/dist/compiled/undici/index.js:1:26669)
at async invokeRequest (/project/sandbox/node_modules/next/dist/server/lib/server-ipc/invoke-request.js:21:12)
at async invokeRender (/project/sandbox/node_modules/next/dist/server/lib/router-server.js:252:29)
at async handleRequest (/project/sandbox/node_modules/next/dist/server/lib/router-server.js:445:24)
at async requestHandler (/project/sandbox/node_modules/next/dist/server/lib/router-server.js:462:13)
at async Server.<anonymous> (/project/sandbox/node_modules/next/dist/server/lib/start-server.js:116:13) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
at write (/project/sandbox/node_modules/next/dist/compiled/undici/index.js:1:67105)
at _resume (/project/sandbox/node_modules/next/dist/compiled/undici/index.js:1:66726)
at resume (/project/sandbox/node_modules/next/dist/compiled/undici/index.js:1:65413)
at connect (/project/sandbox/node_modules/next/dist/compiled/undici/index.js:1:65301) {
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}
Expected Behavior
Sending a GET or similar request with a body may or may not be correct behavior, however it should not be an error for the server. The server should either ignore the body, or return a 400 (or whatever is deemed appropriate).
Probably related: #deleteerro
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
Occurs in dev and production builds
meotimdihia, dylangrandmont, cpatti97100, allybee, cpprookie and 1 more
Metadata
Metadata
Assignees
Labels
RuntimeRelated to Node.js or Edge Runtime with Next.js.Related to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.Issue was opened via the bug report template.lockedstaleThe issue has not seen recent activity.The issue has not seen recent activity.