Bug 1321528: Part 1 - Support suspending requests when processing response headers. r?mayhemer draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 07 Dec 2016 11:04:21 -1000
changeset 447788 182b41b5f0452c94909b039f0e026a0f4c584685
parent 447005 9ff9b1aa382fb49983785d9831b80100a36ecb71
child 447789 775eeb9d1d69e5d50566d5e0a1122445645deb09
push id38163
push usermaglione.k@gmail.com
push dateWed, 07 Dec 2016 21:05:33 +0000
reviewersmayhemer
bugs1321528
milestone53.0a1
Bug 1321528: Part 1 - Support suspending requests when processing response headers. r?mayhemer MozReview-Commit-ID: 8ZtbvqLDksO
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -1990,16 +1990,36 @@ nsHttpChannel::ProcessResponse()
 
     MOZ_ASSERT(!mCachedContentIsValid);
 
     ProcessSSLInformation();
 
     // notify "http-on-examine-response" observers
     gHttpHandler->OnExamineResponse(this);
 
+    return ContinueProcessResponse0();
+}
+
+void
+nsHttpChannel::AsyncContinueProcessResponse()
+{
+    Unused << NS_WARN_IF(NS_FAILED(ContinueProcessResponse0()));
+}
+
+nsresult
+nsHttpChannel::ContinueProcessResponse0()
+{
+    if (mSuspendCount) {
+        LOG(("Waiting until resume to finish processing response [this=%p]\n", this));
+        mCallOnResume = &nsHttpChannel::AsyncContinueProcessResponse;
+        return NS_OK;
+    }
+
+    uint32_t httpStatus = mResponseHead->Status();
+
     // Cookies and Alt-Service should not be handled on proxy failure either.
     // This would be consolidated with ProcessSecurityHeaders but it should
     // happen after OnExamineResponse.
     if (!mTransaction->ProxyConnectFailed() && (httpStatus != 407)) {
         nsAutoCString cookie;
         if (NS_SUCCEEDED(mResponseHead->GetHeader(nsHttp::Set_Cookie, cookie))) {
             SetCookie(cookie.get());
         }
@@ -2029,17 +2049,17 @@ nsHttpChannel::ProcessResponse()
     }
 
     if (mAPIRedirectToURI && !mCanceled) {
         MOZ_ASSERT(!mOnStartRequestCalled);
         nsCOMPtr<nsIURI> redirectTo;
         mAPIRedirectToURI.swap(redirectTo);
 
         PushRedirectAsyncFunc(&nsHttpChannel::ContinueProcessResponse1);
-        rv = StartRedirectChannelToURI(redirectTo, nsIChannelEventSink::REDIRECT_TEMPORARY);
+        nsresult rv = StartRedirectChannelToURI(redirectTo, nsIChannelEventSink::REDIRECT_TEMPORARY);
         if (NS_SUCCEEDED(rv)) {
             return NS_OK;
         }
         PopRedirectAsyncFunc(&nsHttpChannel::ContinueProcessResponse1);
     }
 
     // Hack: ContinueProcessResponse1 uses NS_OK to detect successful
     // redirects, so we distinguish this codepath (a non-redirect that's
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -284,16 +284,18 @@ private:
     nsresult ContinueBeginConnectWithResult();
     void     ContinueBeginConnect();
     nsresult Connect();
     void     SpeculativeConnect();
     nsresult SetupTransaction();
     void     SetupTransactionRequestContext();
     nsresult CallOnStartRequest();
     nsresult ProcessResponse();
+    void     AsyncContinueProcessResponse();
+    nsresult ContinueProcessResponse0();
     nsresult ContinueProcessResponse1(nsresult);
     nsresult ContinueProcessResponse2(nsresult);
     nsresult ProcessNormal();
     nsresult ContinueProcessNormal(nsresult);
     void     ProcessAltService();
     bool     ShouldBypassProcessNotModified();
     nsresult ProcessNotModified();
     nsresult AsyncProcessRedirection(uint32_t httpStatus);