Fetch the Content-Length from the hash bag instead of directly from the channel. r=dwitte, a=betaN+

This commit is contained in:
Byron Milligan 2010-09-07 15:39:28 -07:00
parent eb546c096c
commit b169f8b65d
2 changed files with 13 additions and 9 deletions

View File

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

View File

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