-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending a DELETE request with "Content-Length: 0" fails with a RequestContentLengthMismatchError #2046
Comments
PR welcome |
FYI I'm not sure atm what I think is right or wrong here. What is the realistic scenario where this is a problem? @KhafraDev shouldn't content-length be removed by fetch anyway? Why isn't it? |
I'm using Nuxt, which is using Nitro, whose proxy is based on
|
content-length is removed on redirect in fetch, this bug would also affect undici.request |
I'm aware it affects undici.request, however I wouldn't consider it a bug per se in that context. Might be different for fetch of the spec says to remove it. |
I think failing the request is fine in fetch too. |
@ouuan If you want to make a PR to change this behavior, we'd consider merging it. |
I encountered this error as well. Using tRPC with Next.JS:
|
Should the server ignore |
Servers most likely can decline the request if a
|
Well just spent the entire day to dig through this issue, and also just realized all of our users couldn't DELETE things in the app for a good few months. The discrepancy is where undici expects content length to be 'null' Line 1356 in 5f3b8e1
now I'm fixing this by sending an empty body through all DELETE calls. |
I think we should allow this. If anyone wants to send in a PR, that would be great. |
@KhafraDev is the fix here to allow 0-ish values in client.js? If so I can open a PR and write some tests |
I would only expect it to be set to 0 (outside of where it's already being done) if the method is DELETE and content-length is 0, and definitely a comment linking to this issue. |
Ok got it, just to confirm, would I have to check for both integer 0 and string '0'? For example, the source of the issue comes from node-http-proxy where the content-length is being forced to '0' |
no, it's an integer (the code in the linked issue only checks for 0) |
PR opened, let me know if that's a passable fix @KhafraDev |
Getting this same error when calling a python/flask service hosted on vercel from a server action with fetch
|
Moved to axios and the request seems to be working now. Will report back if there are further issues. |
Bug Description
Sending a DELETE request with "content-length: 0" fails with a RequestContentLengthMismatchError.
The specification says "A user agent SHOULD NOT send a Content-Length header field when the request message does not contain a payload body and the method semantics do not anticipate such a body", but according to RFC 2119, "SHOULD NOT" means "NOT RECOMMENDED", so it's not reasonable to fail a request for this reason.
Even if the Content-Length header "MUST NOT" be sent, the current implementation would still be problematic:
Reproducible By
Expected Behavior
The request succeeds, either as it is or with the Content-Length header removed.
Logs & Screenshots
Environment
Reproducible on both Node v18.15.0 and v19.8.1
Additional Context
Related codes:
undici/lib/client.js
Lines 1333 to 1366 in 5f3b8e1
The text was updated successfully, but these errors were encountered: