fixes bug 210208 "add http-on-examine-merged-response notification" patch=rggammon@alumni.uwaterloo.ca r+sr=darin

This commit is contained in:
darin%meer.net 2003-11-14 20:51:55 +00:00
Родитель a00520fd2c
Коммит 5e79a26f11
4 изменённых файлов: 38 добавлений и 25 удалений

Просмотреть файл

@ -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"
%}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);
}
//-----------------------------------------------------------------------------

Просмотреть файл

@ -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