fix: content type header not present in multipart item #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Content-Type
headers are not present in multipart item file uploads. This can be difficult to see quickly, as some servers (likehttpbin.org
) automatically parse files to the correct content type, so that there is no noticeable effect. Some servers, however, require the content type to be present, which can lead to unexpected and often cryptic errors.Reproduce
"com.lihaoyi" %% "requests" % "0.8.0"
dependency and with a file containing the code below:readme.zip
file and add this file to your project resources.localhost:3000
. Make sure that this webserver is set up to receive multipart upload post requests at the/file
path.MultipartTrial.upload()
and inspect the http packets. You should find a packet containing something like the following, without any content type header:Description
This PR adds the correct
Content-Type
headers to all multipart item file uploads. The result is that the previous request, illustrated above, will produce something similar to the following, this time with the correct content type header:Important Note
After writing tests for this bugfix, I discovered that
httpbin.org
automatically adds the correct content type header to the request, if no header is present. This generates false positives for all tests that are checking for theapplication/octet-stream
content type header on the multipart item. I have left these tests with aTODO
comment for a future fix. Testing these properly will require a different testing strategy and I didn't want to introduce that with this PR.