diff --git a/netwerk/cache/nsCacheEntry.cpp b/netwerk/cache/nsCacheEntry.cpp index f21556215819..1ac4c0c0410a 100644 --- a/netwerk/cache/nsCacheEntry.cpp +++ b/netwerk/cache/nsCacheEntry.cpp @@ -62,6 +62,7 @@ nsCacheEntry::nsCacheEntry(nsCString * key, mLastModified(0), mExpirationTime(nsICache::NO_EXPIRATION_TIME), mFlags(0), + mPredictedDataSize(-1), mDataSize(0), mCacheDevice(nsnull), mData(nsnull) diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index c096e77a5369..8d599983224d 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -755,10 +755,20 @@ nsHttpChannel::CallOnStartRequest() if (mResponseHead && mResponseHead->ContentCharset().IsEmpty()) mResponseHead->SetContentCharset(mContentCharsetHint); - if (mResponseHead) + if (mResponseHead) { SetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, mResponseHead->ContentLength()); - + // If we have a cache entry, set its predicted size to ContentLength to + // avoid caching an entry that will exceed the max size limit. + if (mCacheEntry) { + nsresult rv; + PRInt64 predictedDataSize = -1; // -1 in case GetAsInt64 fails. + GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, + &predictedDataSize); + rv = mCacheEntry->SetPredictedDataSize(predictedDataSize); + if (NS_FAILED(rv)) return rv; + } + } // Allow consumers to override our content type if ((mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) && gIOService->GetContentSniffers().Count() != 0) { @@ -2798,13 +2808,6 @@ nsHttpChannel::InitCacheEntry() rv = AddCacheEntryHeaders(mCacheEntry); if (NS_FAILED(rv)) return rv; - // set predicted size of entry so we do not store anything that will exceed - // the max entry size limit - PRInt64 predictedDataSize; - GetContentLength(&predictedDataSize); - rv = mCacheEntry->SetPredictedDataSize(predictedDataSize); - if (NS_FAILED(rv)) return rv; - mInitedCacheEntry = PR_TRUE; return NS_OK; }