Bug 1199049 - Part 8: Use Necko-level CORS preflights in fetch; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 27 Aug 2015 14:41:58 -0400
changeset 294827 c7445d6f1d2db049728062c09a8b305877cd5c2e
parent 294826 5015d235ae9579757e796da3a78c38bc3c1691a7
child 294828 27203d34c6842f9a789bbaec8ba436e4820662c4
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1199049
milestone43.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 1199049 - Part 8: Use Necko-level CORS preflights in fetch; r=jdm
dom/fetch/FetchDriver.cpp
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -613,28 +613,29 @@ FetchDriver::HttpFetch(bool aCORSFlag, b
   // If preflight is required, start a "CORS preflight fetch"
   // https://fetch.spec.whatwg.org/#cors-preflight-fetch-0. All the
   // implementation is handled by NS_StartCORSPreflight, we just set up the
   // unsafeHeaders so they can be verified against the response's
   // "Access-Control-Allow-Headers" header.
   if (aCORSPreflightFlag) {
     MOZ_ASSERT(mRequest->Mode() != RequestMode::No_cors,
                "FetchDriver::ContinueFetch() should ensure that the request is not no-cors");
-    nsCOMPtr<nsIChannel> preflightChannel;
+    MOZ_ASSERT(httpChan, "CORS preflight can only be used with HTTP channels");
     nsAutoTArray<nsCString, 5> unsafeHeaders;
     mRequest->Headers()->GetUnsafeHeaders(unsafeHeaders);
 
-    rv = NS_StartCORSPreflight(chan, listener, mPrincipal,
-                               useCredentials,
-                               unsafeHeaders,
-                               getter_AddRefs(preflightChannel));
-  } else {
-    rv = chan->AsyncOpen(listener, nullptr);
+    nsCOMPtr<nsIHttpChannelInternal> internalChan = do_QueryInterface(httpChan);
+    rv = internalChan->SetCorsPreflightParameters(unsafeHeaders, useCredentials, mPrincipal);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return FailWithNetworkError();
+    }
   }
 
+  rv = chan->AsyncOpen(listener, nullptr);
+
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return FailWithNetworkError();
   }
 
   // Step 4 onwards of "HTTP Fetch" is handled internally by Necko.
   return NS_OK;
 }