Bug 1485427 - Add two assertions ensuring that request observers are (not) fired at the right times; r=mayhemer
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 22 Aug 2018 13:58:18 -0400
changeset 481522 5d6bf0312e088bb2424a8177589a9fd4aa44bfa8
parent 481521 701ceb33e3d751be2faa8bf1b99bd14d51f3eadb
child 481523 f0c6e521429cfaff0585ec6eaf734e9fcf873f8a
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersmayhemer
bugs1485427
milestone63.0a1
Bug 1485427 - Add two assertions ensuring that request observers are (not) fired at the right times; r=mayhemer
netwerk/protocol/http/HttpBaseChannel.h
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/protocol/http/HttpBaseChannel.h
+++ b/netwerk/protocol/http/HttpBaseChannel.h
@@ -448,16 +448,17 @@ protected:
   void AddCookiesToRequest();
   virtual MOZ_MUST_USE nsresult
   SetupReplacementChannel(nsIURI *, nsIChannel *, bool preserveMethod,
                           uint32_t redirectFlags);
 
   // bundle calling OMR observers and marking flag into one function
   inline void CallOnModifyRequestObservers() {
     gHttpHandler->OnModifyRequest(this);
+    MOZ_ASSERT(!mRequestObserversCalled);
     mRequestObserversCalled = true;
   }
 
   // Helper function to simplify getting notification callbacks.
   template <class T>
   void GetCallback(nsCOMPtr<T> &aResult)
   {
     NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -7056,16 +7056,18 @@ nsHttpChannel::GetRequestMethod(nsACStri
 // nsHttpChannel::nsIRequestObserver
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsHttpChannel::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
 {
     nsresult rv;
 
+    MOZ_ASSERT(mRequestObserversCalled);
+
     AUTO_PROFILER_LABEL("nsHttpChannel::OnStartRequest", NETWORK);
 
     if (!(mCanceled || NS_FAILED(mStatus)) && !WRONG_RACING_RESPONSE_SOURCE(request)) {
         // capture the request's status, so our consumers will know ASAP of any
         // connection failures, etc - bug 93581
         nsresult status;
         request->GetStatus(&status);
         mStatus = status;
@@ -8245,16 +8247,20 @@ nsHttpChannel::DoAuthRetry(nsAHttpConnec
 
     MOZ_ASSERT(!mTransaction, "should not have a transaction");
     nsresult rv;
 
     // toggle mIsPending to allow nsIObserver implementations to modify
     // the request headers (bug 95044).
     mIsPending = false;
 
+    // Reset mRequestObserversCalled because we've probably called the request
+    // observers once already.
+    mRequestObserversCalled = false;
+
     // fetch cookies, and add them to the request header.
     // the server response could have included cookies that must be sent with
     // this authentication attempt (bug 84794).
     // TODO: save cookies from auth response and send them here (bug 572151).
     AddCookiesToRequest();
 
     // notify "http-on-modify-request" observers
     CallOnModifyRequestObservers();