question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multipart should not add "Content-Length"

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
JakeWhartoncommented, Dec 21, 2015

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.

1reaction
swankjessecommented, Feb 22, 2016

No action for us to take here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found