Bug 1454325 - update XHR upload content-type handling to match the spec. r=baku
☠☠ backed out by dd235c6dd881 ☠ ☠
authorThomas Wisniewski <twisniewski@mozilla.com>
Mon, 18 Mar 2019 23:41:34 +0000
changeset 464889 f525479fabd6ff2bbd6cce61bced03824b4e2c90
parent 464888 75b190178c5a3cf1aa1cefc0ab2139f7078d126c
child 464890 8536a746d9cc72bb27c510a40ae7518c2e630ea2
push id35727
push userdvarga@mozilla.com
push dateTue, 19 Mar 2019 09:48:59 +0000
treeherdermozilla-central@70baa37ae1eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1454325
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1454325 - update XHR upload content-type handling to match the spec. r=baku update XHR upload content-type handling to match the spec Differential Revision: https://phabricator.services.mozilla.com/D23251
dom/xhr/XMLHttpRequestMainThread.cpp
modules/libpref/init/StaticPrefList.h
testing/web-platform/meta/xhr/send-content-type-charset.htm.ini
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -2771,26 +2771,29 @@ nsresult XMLHttpRequestMainThread::SendI
 
     if (uploadStream) {
       // If author set no Content-Type, use the default from GetAsStream().
       mAuthorRequestHeaders.Get("content-type", uploadContentType);
       if (uploadContentType.IsVoid()) {
         uploadContentType = defaultContentType;
       } else if (aBodyIsDocumentOrString &&
                  StaticPrefs::dom_xhr_standard_content_type_normalization()) {
-        UniquePtr<CMimeType> parsed = CMimeType::Parse(uploadContentType);
-        if (parsed && parsed->HasParameter(kLiteralString_charset)) {
-          parsed->SetParameterValue(kLiteralString_charset,
-                                    kLiteralString_UTF_8);
-          parsed->Serialize(uploadContentType);
+        UniquePtr<CMimeType> contentTypeRecord =
+            CMimeType::Parse(uploadContentType);
+        nsAutoCString charset;
+        if (contentTypeRecord &&
+            contentTypeRecord->GetParameterValue(kLiteralString_charset,
+                                                 charset) &&
+            !charset.EqualsIgnoreCase("utf-8")) {
+          contentTypeRecord->SetParameterValue(kLiteralString_charset,
+                                               kLiteralString_UTF_8);
+          contentTypeRecord->Serialize(uploadContentType);
         }
-      }
-
-      // We don't want to set a charset for streams.
-      if (!charset.IsEmpty()) {
+      } else if (!charset.IsEmpty()) {
+        // We don't want to set a charset for streams.
         // Replace all case-insensitive matches of the charset in the
         // content-type with the correct case.
         RequestHeaders::CharsetIterator iter(uploadContentType);
         const nsCaseInsensitiveCStringComparator cmp;
         while (iter.Next()) {
           if (!iter.Equals(charset, cmp)) {
             iter.Replace(charset);
           }
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -478,21 +478,20 @@ VARCACHE_PREF(
 
 VARCACHE_PREF(
   "dom.worker.use_medium_high_event_queue",
    dom_worker_use_medium_high_event_queue,
   RelaxedAtomicBool, true
 )
 
 // Enable content type normalization of XHR uploads via MIME Sniffing standard
-// Disabled for now in bz1499136
 VARCACHE_PREF(
   "dom.xhr.standard_content_type_normalization",
    dom_xhr_standard_content_type_normalization,
-  RelaxedAtomicBool, false
+  RelaxedAtomicBool, true
 )
 
 // Block multiple external protocol URLs in iframes per single event.
 VARCACHE_PREF(
   "dom.block_external_protocol_in_iframes",
    dom_block_external_protocol_in_iframes,
   bool, true
 )
deleted file mode 100644
--- a/testing/web-platform/meta/xhr/send-content-type-charset.htm.ini
+++ /dev/null
@@ -1,19 +0,0 @@
-[send-content-type-charset.htm]
-  [charset with space that is UTF-8 does not change]
-    expected: FAIL
-
-  [charset in double quotes with backslashes that is UTF-8 does not change]
-    expected: FAIL
-
-  [If charset= param is UTF-8 (case-insensitive), it should not be changed (bogus charset)]
-    expected: FAIL
-
-  [If charset= param is UTF-8 (case-insensitive), it should not be changed]
-    expected: FAIL
-
-  [charset in double quotes that is UTF-8 does not change]
-    expected: FAIL
-
-  [charset with trailing space that is UTF-8 does not change]
-    expected: FAIL
-