From c739c5639b4b017119a11eacc39b52e1fd4db4fa Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Fri, 14 Dec 2001 22:53:13 +0000 Subject: [PATCH] fixes bug 114286 "No way to determine if a http request was a 304 or not." r=pavlov, sr=mscott --- netwerk/base/public/nsICachingChannel.idl | 7 +++++++ netwerk/protocol/http/src/nsHttpChannel.cpp | 19 +++++++++++++++++-- netwerk/protocol/http/src/nsHttpChannel.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/netwerk/base/public/nsICachingChannel.idl b/netwerk/base/public/nsICachingChannel.idl index 5644b09c4dec..24ca955be861 100644 --- a/netwerk/base/public/nsICachingChannel.idl +++ b/netwerk/base/public/nsICachingChannel.idl @@ -93,6 +93,13 @@ interface nsICachingChannel : nsISupports * an error if cacheAsFile is false. */ readonly attribute nsIFile cacheFile; + + /** + * TRUE if this channel's data is being loaded from the cache. This value + * is undefined before the channel fires its OnStartRequest notification + * and after the channel fires its OnStopRequest notification. + */ + boolean isFromCache(); }; %{C++ diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index edffbad19249..aeeefe6abc7c 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -68,6 +68,7 @@ nsHttpChannel::nsHttpChannel() , mFromCacheOnly(PR_FALSE) , mCachedContentIsValid(PR_FALSE) , mResponseHeadersModified(PR_FALSE) + , mCanceled(PR_FALSE) { LOG(("Creating nsHttpChannel @%x\n", this)); @@ -1751,6 +1752,7 @@ NS_IMETHODIMP nsHttpChannel::Cancel(nsresult status) { LOG(("nsHttpChannel::Cancel [this=%x status=%x]\n", this, status)); + mCanceled = PR_TRUE; mStatus = status; if (mTransaction) mTransaction->Cancel(status); @@ -2387,8 +2389,14 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st mListenerContext = 0; } - if (mCacheEntry) - CloseCacheEntry(status); + if (mCacheEntry) { + // we don't want to discard the cache entry if canceled and + // reading from the cache. + if (mCanceled && (request == mCacheReadRequest)) + CloseCacheEntry(NS_OK); + else + CloseCacheEntry(status); + } if (mLoadGroup) mLoadGroup->RemoveRequest(this, nsnull, status); @@ -2571,6 +2579,13 @@ nsHttpChannel::GetCacheFile(nsIFile **cacheFile) return mCacheEntry->GetFile(cacheFile); } +NS_IMETHODIMP +nsHttpChannel::IsFromCache(PRBool *value) +{ + *value = (mCacheReadRequest != nsnull); + return NS_OK; +} + //----------------------------------------------------------------------------- // nsHttpChannel::nsICacheListener //----------------------------------------------------------------------------- diff --git a/netwerk/protocol/http/src/nsHttpChannel.h b/netwerk/protocol/http/src/nsHttpChannel.h index ecf1286c6ab1..6e260d68a8e3 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.h +++ b/netwerk/protocol/http/src/nsHttpChannel.h @@ -171,6 +171,7 @@ private: PRPackedBool mFromCacheOnly; PRPackedBool mCachedContentIsValid; PRPackedBool mResponseHeadersModified; + PRPackedBool mCanceled; }; #endif // nsHttpChannel_h__