Multipart should not add "Content-Length"
See original GitHub issueI found following request will cause server error The body of your POST request is not well-formed multipart/form-data
--be1563be-4245-4ac5-8a95-498ba5b57ba8
content-disposition: form-data; name="name"
Content-Length: 22
ic_menu_white_24dp.png
...
--d4653e4a-9a5d-42e5-8a49-fcafbe9c673c
content-disposition: form-data; name="file"; filename="ic_menu_white_24dp.png"
Content-Type: image/png
Content-Length: 92
In okhttp code,
long contentLength = body.contentLength();
if (contentLength != -1) {
sink.writeUtf8("Content-Length: ")
.writeDecimalLong(contentLength)
.write(CRLF);
} else if (countBytes) {
// We can't measure the body's size without the sizes of its components.
byteCountBuffer.clear();
return -1L;
}
And I google the rfc1867, in the document, there is not description for adding “Content-Length”, so maybe it is a bug for okhttp.
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How is an HTTP multipart "Content-length" header value ...
The multipart request's "Content-length" is computed from the first byte of the boundary sequence following the header section's blank line, and ...
Read more >1434553 - Content-Length is wrong for multipart/form-data ...
What we could try is to add a new thing on streams that asks for the data size (even if not all the...
Read more >Trust the Content-Length header - Medium
The solution is easier. Trust the Content-Length header and validate if the size is ok. The rest should be handled by your server....
Read more >File uploads (profile image, simple, resumable uploads)
You must provide a top-level Content-Length header that declares the length of the entire request body in bytes. · The first part of...
Read more >Multipart Requests - Swagger
As you can see, a multipart request can include various data: strings, objects in JSON format, and binary data. You can also specify...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sounds like a server bug. Any number of headers are allowed in the part bodies so if the length isn’t used it should simply be ignored or if it is used the number if accurate so the server is using it incorrectly.
No action for us to take here.