From 208f93e405a1f6719d205fa88074b25edb8683f5 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 30 Dec 2015 18:25:48 -0500 Subject: [PATCH] Bug 1233245 - Propagate the interception information in the non-e10s case for all HTTP redirects, not just the internal ones; r=jdm Doing this work in StartRedirectChannelToURI() was causing us to not set the bypass service worker flag properly in the case of real HTTP redirects. This patch also fixes the incorrect test expectation value. --- netwerk/protocol/http/nsHttpChannel.cpp | 33 ++++++++++--------- .../navigation-redirect.https.html | 4 +-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index c7b3f619495b..321d1052404f 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -2012,21 +2012,12 @@ nsHttpChannel::StartRedirectChannelToURI(nsIURI *upgradedURI, uint32_t flags) // Inform consumers about this fake redirect mRedirectChannel = newChannel; - if (!(flags & nsIChannelEventSink::REDIRECT_STS_UPGRADE)) { - // Ensure that internally-redirected channels cannot be intercepted, which would look - // like two separate requests to the nsINetworkInterceptController. - if (mInterceptCache == INTERCEPTED) { - nsCOMPtr httpRedirect = do_QueryInterface(mRedirectChannel); - if (httpRedirect) { - httpRedirect->ForceIntercepted(mInterceptionID); - } - } else { - nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL; - rv = mRedirectChannel->GetLoadFlags(&loadFlags); - NS_ENSURE_SUCCESS(rv, rv); - loadFlags |= nsIChannel::LOAD_BYPASS_SERVICE_WORKER; - rv = mRedirectChannel->SetLoadFlags(loadFlags); - NS_ENSURE_SUCCESS(rv, rv); + if (!(flags & nsIChannelEventSink::REDIRECT_STS_UPGRADE) && + mInterceptCache == INTERCEPTED) { + // Mark the channel as intercepted in order to propagate the response URL. + nsCOMPtr httpRedirect = do_QueryInterface(mRedirectChannel); + if (httpRedirect) { + httpRedirect->ForceIntercepted(mInterceptionID); } } @@ -4605,6 +4596,18 @@ nsHttpChannel::SetupReplacementChannel(nsIURI *newURI, resumableChannel->ResumeAt(mStartPos, mEntityID); } + if (!(redirectFlags & nsIChannelEventSink::REDIRECT_STS_UPGRADE) && + mInterceptCache != INTERCEPTED) { + // Ensure that internally-redirected channels cannot be intercepted, which would look + // like two separate requests to the nsINetworkInterceptController. + nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL; + rv = newChannel->GetLoadFlags(&loadFlags); + NS_ENSURE_SUCCESS(rv, rv); + loadFlags |= nsIChannel::LOAD_BYPASS_SERVICE_WORKER; + rv = newChannel->SetLoadFlags(loadFlags); + NS_ENSURE_SUCCESS(rv, rv); + } + return NS_OK; } diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/navigation-redirect.https.html b/testing/web-platform/mozilla/tests/service-workers/service-worker/navigation-redirect.https.html index 7b606cf0c3c0..2e842add240b 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/navigation-redirect.https.html +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/navigation-redirect.https.html @@ -150,7 +150,7 @@ promise_test(function(t) { return test_redirect( OUT_SCOPE + 'url=' + encodeURIComponent(SCOPE1), SCOPE1, - [[SCOPE1], [], []]); + [[], [], []]); }); }, 'Normal redirect to same-origin scope.'); promise_test(function(t) { @@ -158,7 +158,7 @@ promise_test(function(t) { return test_redirect( OUT_SCOPE + 'url=' + encodeURIComponent(OTHER_ORIGIN_SCOPE), OTHER_ORIGIN_SCOPE, - [[], [], [OTHER_ORIGIN_SCOPE]]); + [[], [], []]); }); }, 'Normal redirect to other-origin scope.');