Bug 1367810 - Don't race cache with network when CORS preflight is required for a channel r=michal draft
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 15 Jun 2017 15:45:40 +0300
changeset 594761 f70b22348c297a37b647f9bfd3c65bd8bdb45461
parent 593717 b266a8d8fd595b84a7d6218d7b8c6b7af0b5027c
child 633513 db2bc3b19463fd290459f135dd558d63d77caadf
push id64128
push uservalentin.gosu@gmail.com
push dateThu, 15 Jun 2017 12:46:13 +0000
reviewersmichal
bugs1367810
milestone56.0a1
Bug 1367810 - Don't race cache with network when CORS preflight is required for a channel r=michal MozReview-Commit-ID: CPyafHsMYoy
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -9106,16 +9106,26 @@ nsHttpChannel::TriggerNetwork(int32_t aT
 nsresult
 nsHttpChannel::MaybeRaceCacheWithNetwork()
 {
     // Don't trigger the network if the load flags say so.
     if (mLoadFlags & (LOAD_ONLY_FROM_CACHE | LOAD_NO_NETWORK_IO)) {
         return NS_OK;
     }
 
+    // We must not race if the channel has a failure status code.
+    if (NS_FAILED(mStatus)) {
+        return NS_OK;
+    }
+
+    // If a CORS Preflight is required we must not race.
+    if (mRequireCORSPreflight && !mIsCorsPreflightDone) {
+        return NS_OK;
+    }
+
     uint32_t threshold = mCacheOpenWithPriority ? sRCWNQueueSizePriority
                                                 : sRCWNQueueSizeNormal;
     // No need to trigger to trigger the racing, since most likely the cache
     // will be faster.
     if (mCacheQueueSizeWhenOpen < threshold) {
         return NS_OK;
     }