Bug 1328761 - Part 2: Update some FetchDriver comments to more clearly reflect reality. r=bkelly, a=jcristau
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 14 Jan 2017 22:43:17 -0500
changeset 353642 2d2e70db03c3c09482b464c00a8c9a81d5a0a1c6
parent 353641 1e9635dd5012725bd5a7d8559e3c8dd3c2ce676f
child 353643 29d706c05b1d708775b52fdf1003f217324c7bb5
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly, jcristau
bugs1328761
milestone52.0a2
Bug 1328761 - Part 2: Update some FetchDriver comments to more clearly reflect reality. r=bkelly, a=jcristau
dom/fetch/FetchDriver.cpp
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -336,22 +336,32 @@ FetchDriver::HttpFetch()
   // Step 5. Proxy authentication will be handled by Necko.
 
   // Continue setting up 'HTTPRequest'. Content-Type and body data.
   nsCOMPtr<nsIUploadChannel2> uploadChan = do_QueryInterface(chan);
   if (uploadChan) {
     nsAutoCString contentType;
     ErrorResult result;
     mRequest->Headers()->GetFirst(NS_LITERAL_CSTRING("content-type"), contentType, result);
-    // This is an error because the Request constructor explicitly extracts and
-    // sets a content-type per spec.
+    // We don't actually expect "result" to have failed here: that only happens
+    // for invalid header names.  But if for some reason it did, just propagate
+    // it out.
     if (result.Failed()) {
       return result.StealNSResult();
     }
 
+    // Now contentType is the header that was set in mRequest->Headers(), or a
+    // void string if no header was set.
+#ifdef DEBUG
+    bool hasContentTypeHeader =
+      mRequest->Headers()->Has(NS_LITERAL_CSTRING("content-type"), result);
+    MOZ_ASSERT(!result.Failed());
+    MOZ_ASSERT_IF(!hasContentTypeHeader, contentType.IsVoid());
+#endif // DEBUG
+
     nsCOMPtr<nsIInputStream> bodyStream;
     mRequest->GetBody(getter_AddRefs(bodyStream));
     if (bodyStream) {
       nsAutoCString method;
       mRequest->GetMethod(method);
       rv = uploadChan->ExplicitSetUploadStream(bodyStream, contentType, -1, method, false /* aStreamHasHeaders */);
       NS_ENSURE_SUCCESS(rv, rv);
     }