From 5e79a26f11c58aa9e3e9e41b7bb85f31bb7cc0af Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Fri, 14 Nov 2003 20:51:55 +0000 Subject: [PATCH] fixes bug 210208 "add http-on-examine-merged-response notification" patch=rggammon@alumni.uwaterloo.ca r+sr=darin --- .../http/public/nsIHttpProtocolHandler.idl | 7 +++++++ netwerk/protocol/http/src/nsHttpChannel.cpp | 17 +++++++++------ netwerk/protocol/http/src/nsHttpHandler.cpp | 18 ++++------------ netwerk/protocol/http/src/nsHttpHandler.h | 21 ++++++++++++++----- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl b/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl index 921524e5b0e..8b7f70c0d55 100644 --- a/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl +++ b/netwerk/protocol/http/public/nsIHttpProtocolHandler.idl @@ -133,4 +133,11 @@ interface nsIHttpProtocolHandler : nsIProxiedProtocolHandler * the notification is the nsIHttpChannel instance. */ #define NS_HTTP_ON_EXAMINE_RESPONSE_TOPIC "http-on-examine-response" + +/** + * The observer of this topic is notified after the received HTTP response + * is merged with data from the browser cache. This means that, among other + * things, the Content-Type header will be set correctly. + */ +#define NS_HTTP_ON_EXAMINE_MERGED_RESPONSE_TOPIC "http-on-examine-merged-response" %} diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index 71718f34e2d..bb8b901dda9 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -654,8 +654,7 @@ nsHttpChannel::ProcessResponse() SetCookie(mResponseHead->PeekHeader(nsHttp::Set_Cookie)); // notify nsIHttpNotify implementations - rv = gHttpHandler->OnExamineResponse(this); - NS_ASSERTION(NS_SUCCEEDED(rv), "OnExamineResponse failed"); + gHttpHandler->OnExamineResponse(this); // handle different server response categories switch (httpStatus) { @@ -976,6 +975,10 @@ nsHttpChannel::ProcessPartialContent() rv = UpdateExpirationTime(); if (NS_FAILED(rv)) return rv; + // notify observers interested in looking at a reponse that has been + // merged with any cached headers + gHttpHandler->OnExamineMergedResponse(this); + // the cached content is valid, although incomplete. mCachedContentIsValid = PR_TRUE; return ReadFromCache(); @@ -1050,6 +1053,10 @@ nsHttpChannel::ProcessNotModified() rv = UpdateExpirationTime(); if (NS_FAILED(rv)) return rv; + // notify observers interested in looking at a reponse that has been + // merged with any cached headers + gHttpHandler->OnExamineMergedResponse(this); + mCachedContentIsValid = PR_TRUE; rv = ReadFromCache(); if (NS_FAILED(rv)) return rv; @@ -2748,8 +2755,7 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context) AddCookiesToRequest(); // Notify nsIHttpNotify implementations - rv = gHttpHandler->OnModifyRequest(this); - NS_ASSERTION(NS_SUCCEEDED(rv), "OnModifyRequest failed"); + gHttpHandler->OnModifyRequest(this); mIsPending = PR_TRUE; @@ -3660,8 +3666,7 @@ nsHttpChannel::DoAuthRetry(nsAHttpConnection *conn) AddCookiesToRequest(); // notify nsIHttpNotify implementations - rv = gHttpHandler->OnModifyRequest(this); - NS_ASSERTION(NS_SUCCEEDED(rv), "OnModifyRequest failed"); + gHttpHandler->OnModifyRequest(this); mIsPending = PR_TRUE; diff --git a/netwerk/protocol/http/src/nsHttpHandler.cpp b/netwerk/protocol/http/src/nsHttpHandler.cpp index 58ef45872b8..eed152e2a79 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -471,22 +471,12 @@ nsHttpHandler::GetIOService(nsIIOService** result) } -nsresult -nsHttpHandler::OnModifyRequest(nsIHttpChannel *chan) +void +nsHttpHandler::NotifyObservers(nsIHttpChannel *chan, const char *event) { - LOG(("nsHttpHandler::OnModifyRequest [chan=%x]\n", chan)); + LOG(("nsHttpHandler::NotifyObservers [chan=%x event=\"%s\"]\n", chan, event)); if (mObserverService) - mObserverService->NotifyObservers(chan, NS_HTTP_ON_MODIFY_REQUEST_TOPIC, nsnull); - return NS_OK; -} - -nsresult -nsHttpHandler::OnExamineResponse(nsIHttpChannel *chan) -{ - LOG(("nsHttpHandler::OnExamineResponse [chan=%x]\n", chan)); - if (mObserverService) - mObserverService->NotifyObservers(chan, NS_HTTP_ON_EXAMINE_RESPONSE_TOPIC, nsnull); - return NS_OK; + mObserverService->NotifyObservers(chan, event, nsnull); } //----------------------------------------------------------------------------- diff --git a/netwerk/protocol/http/src/nsHttpHandler.h b/netwerk/protocol/http/src/nsHttpHandler.h index 6b1f4a49459..c21cd795c09 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.h +++ b/netwerk/protocol/http/src/nsHttpHandler.h @@ -156,10 +156,22 @@ public: nsICookieService * GetCookieService(); // not addrefed // Called by the channel before writing a request - nsresult OnModifyRequest(nsIHttpChannel *); + void OnModifyRequest(nsIHttpChannel *chan) + { + NotifyObservers(chan, NS_HTTP_ON_MODIFY_REQUEST_TOPIC); + } // Called by the channel once headers are available - nsresult OnExamineResponse(nsIHttpChannel *); + void OnExamineResponse(nsIHttpChannel *chan) + { + NotifyObservers(chan, NS_HTTP_ON_EXAMINE_RESPONSE_TOPIC); + } + + // Called by the channel once headers have been merged with cached headers + void OnExamineMergedResponse(nsIHttpChannel *chan) + { + NotifyObservers(chan, NS_HTTP_ON_EXAMINE_MERGED_RESPONSE_TOPIC); + } private: @@ -176,13 +188,12 @@ private: nsresult SetAcceptEncodings(const char *); nsresult SetAcceptCharsets(const char *); - // timer callback for cleansing the idle connection list - //static void DeadConnectionCleanupCB(nsITimer *, void *); - nsresult InitConnectionMgr(); void StartPruneDeadConnectionsTimer(); void StopPruneDeadConnectionsTimer(); + void NotifyObservers(nsIHttpChannel *chan, const char *event); + private: // cached services