RESOLVED DUPLICATE of bug 211999159210
Empty Content-Type header sent when uploading a file using XMLHttpRequest and type-less Blob
https://bugs.webkit.org/show_bug.cgi?id=159210
Summary Empty Content-Type header sent when uploading a file using XMLHttpRequest and...
Greg B
Reported 2016-06-28 05:00:29 PDT
In my Javascript application I upload files to Amazon S3 bucket using XMLHttpRequests using type-less blobs e.g. var myTypeLessBlob = new window.Blob([some Uint8Array of data]). The reason I'm not specifying a Content-Type (instead of using, say, application/octet-stream or binary/octet-stream, which is what this data is technically) is because I need to support a legacy (cannot modify the code of) version of Java application which fetches these uploaded documents later, and S3 expects the Content-Type header value that was specified during upload to be the same during download later - and the legacy app doesn't specify Content-Type during its uploads or downloads. Anywho, this type-less blob approach for upload and subsequent download seems to work fine for me in Chrome, Firefox, IE11, Microsoft Edge. That is, the Content-Type header does not get sent in a PUT request to the server and later on when I download the document it's the Amazon S3 that tells me that its in fact binary/octet-stream in its response header. However when using Safari, I noticed that for some reason the Content-Type header gets sent as an empty string during upload - which results in the same behaviour during the subsequent download, which causes issues when I try to download my Safari-uploaded file in those other browsers. Is there some reason Safari/Webkit is behaving differently to other browsers in this regard? cheers, Greg
Attachments
Test patch (5.93 KB, patch)
2016-07-05 00:10 PDT, youenn fablet
no flags
Patch (6.37 KB, patch)
2016-10-24 00:02 PDT, youenn fablet
no flags
youenn fablet
Comment 1 2016-06-28 06:03:44 PDT
SO, XMLHttpRequest implementation sets explicitly an empty string content type in case of a blob without mime type. According the source code, it says that it is mandated by the file API spec. I am wondering whether that still holds and what is the rationale here.
youenn fablet
Comment 2 2016-06-28 06:09:47 PDT
According to https://xhr.spec.whatwg.org/#the-send()-method and https://fetch.spec.whatwg.org/#concept-bodyinit-extract, no Content-Type header should actually be sent in the case of a type-less blob.
youenn fablet
Comment 3 2016-06-28 06:21:46 PDT
(In reply to comment #2) > According to https://xhr.spec.whatwg.org/#the-send()-method and > https://fetch.spec.whatwg.org/#concept-bodyinit-extract, no Content-Type > header should actually be sent in the case of a type-less blob. http://www.w3.org/TR/XMLHttpRequest/#the-send()-method also agrees with not sending an empty-string CT header in that case.
youenn fablet
Comment 4 2016-07-05 00:10:00 PDT
Created attachment 282753 [details] Test patch
youenn fablet
Comment 5 2016-07-05 00:15:14 PDT
(In reply to comment #4) > Created attachment 282753 [details] > Test patch The following patch solves the issue for soup-based ports. It makes things worse for Mac-based ports as a "Content-Type: application/x-www-form-urlencoded" is added when none is provided. It might be the underlying HTTP library that does so when requested to upload some content.
youenn fablet
Comment 6 2016-07-05 09:32:25 PDT
Greg, it might be the case that using PUT in lieu of POST might not cause that issue. I am not sure whether that would work for your case, but just in case...
Greg B
Comment 7 2016-07-29 00:51:20 PDT
Hi Youenn, can you please clarify what you mean by soup-based/Mac-based? Personally I'm mostly after this behaviour corrected in Safari browser. Also, how do we get someone to review your patch and where to from here? In regards to your last comment, I was already using PUT request when I noticed the initial issue that I reported.
youenn fablet
Comment 8 2016-07-29 06:35:54 PDT
(In reply to comment #7) > Hi Youenn, can you please clarify what you mean by soup-based/Mac-based? > Personally I'm mostly after this behaviour corrected in Safari browser. > Also, how do we get someone to review your patch and where to from here? In > regards to your last comment, I was already using PUT request when I noticed > the initial issue that I reported. The proposed patch calls for a change in the HTTP library below WebKit for Mac ports, hence Safari. Once updated, it will be time to review and hopefully land this patch.
youenn fablet
Comment 9 2016-10-24 00:02:23 PDT
youenn fablet
Comment 10 2016-10-24 00:15:20 PDT
(In reply to comment #6) > Greg, it might be the case that using PUT in lieu of POST might not cause > that issue. > I am not sure whether that would work for your case, but just in case... OK, PUT with the above patch should work for you. POST needs additional care at a layer below. Latest patch tries to ship the change for PUT.
youenn fablet
Comment 11 2016-10-24 00:15:37 PDT
Darin Adler
Comment 12 2016-10-24 10:16:17 PDT
Comment on attachment 292587 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=292587&action=review > Source/WebCore/xml/XMLHttpRequest.cpp:574 > + else if (m_method == "POST") { > + // See rdar://problem/27173554. CFNetwork will put a default Content-Type value if we do no set it, but only for POST. Why would we have cross-platform code to work around a CFNetwork-specific bug?
youenn fablet
Comment 13 2016-10-24 14:46:50 PDT
(In reply to comment #12) > Comment on attachment 292587 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=292587&action=review > > > Source/WebCore/xml/XMLHttpRequest.cpp:574 > > + else if (m_method == "POST") { > > + // See rdar://problem/27173554. CFNetwork will put a default Content-Type value if we do no set it, but only for POST. > > Why would we have cross-platform code to work around a CFNetwork-specific > bug? Agreed. I thought it was ok to progressively make the correct behavior accross all methods. We can also improve this patch to fix it permanently in XHR and temporarily in CFNetwork binding code. This may be indeed nicer.
Darin Adler
Comment 14 2016-10-24 22:06:42 PDT
(In reply to comment #13) > I thought it was ok to progressively make the correct behavior > accross all methods. Sorry, I don’t understand what that means.
youenn fablet
Comment 15 2016-10-25 00:45:26 PDT
There are different options: - Option 1 Wait for CF Network to get fixed so that we can fully align with XHR spec and have no content-type set in all cases. - Option 2 Align XHR to the spec for the methods that do not exhibit the CF network issue. Status quo for the POST method. - Option 3 Align XHR to the spec for all methods. When CFNetwork gets updated, POST content-type will be fixed. - Option 4 Align XHR to the spec for all methods. Update CF network binding code to keep the status quo for the POST method. I initially chose option 1, but option 2 allows to ship some improvements beneficial for all ports and many users even though CFNetwork does not ship the fix. Option 3 is ok for a new API like fetch API, but for XHR, this does not seem right in terms of compatibility. Option 4 would probably be nicer but we would need to apply this trick at the CF network platform code for XHR requests only (It is not appealing to apply this trick for fetch API requests).
Rob Buis
Comment 16 2018-09-23 00:08:39 PDT
*** Bug 189886 has been marked as a duplicate of this bug. ***
Rob Buis
Comment 17 2020-06-08 10:57:26 PDT
This seems like a duplicate of https://bugs.webkit.org/show_bug.cgi?id=211999, which is up for review.
youenn fablet
Comment 18 2020-06-09 02:04:53 PDT
*** This bug has been marked as a duplicate of bug 211999 ***
Note You need to log in before you can comment on or make changes to this bug.