Bug 913810 - make nsHttpChannel properly react to FILE_NOT_FOUND from the cache, r=michal

This commit is contained in:
Honza Bambas 2014-04-26 18:42:07 +02:00
parent 10b71f4c30
commit cd415d3c36
2 changed files with 19 additions and 5 deletions

View File

@ -76,6 +76,10 @@ namespace {
(loadFlags & (nsIRequest::LOAD_BYPASS_CACHE | \
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE))
#define CACHE_FILE_GONE(result) \
((result) == NS_ERROR_FILE_NOT_FOUND || \
(result) == NS_ERROR_FILE_CORRUPTED)
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
static NS_DEFINE_CID(kStreamTransportServiceCID,
NS_STREAMTRANSPORTSERVICE_CID);
@ -1615,7 +1619,8 @@ nsHttpChannel::StartRedirectChannelToHttps()
else
upgradedURI->SetPort(oldPort);
return StartRedirectChannelToURI(upgradedURI);
return StartRedirectChannelToURI(upgradedURI,
nsIChannelEventSink::REDIRECT_PERMANENT);
}
void
@ -1630,7 +1635,8 @@ nsHttpChannel::HandleAsyncAPIRedirect()
return;
}
nsresult rv = StartRedirectChannelToURI(mAPIRedirectToURI);
nsresult rv = StartRedirectChannelToURI(mAPIRedirectToURI,
nsIChannelEventSink::REDIRECT_PERMANENT);
if (NS_FAILED(rv))
ContinueAsyncRedirectChannelToURI(rv);
@ -1638,7 +1644,7 @@ nsHttpChannel::HandleAsyncAPIRedirect()
}
nsresult
nsHttpChannel::StartRedirectChannelToURI(nsIURI *upgradedURI)
nsHttpChannel::StartRedirectChannelToURI(nsIURI *upgradedURI, uint32_t flags)
{
nsresult rv = NS_OK;
LOG(("nsHttpChannel::StartRedirectChannelToURI()\n"));
@ -1657,7 +1663,6 @@ nsHttpChannel::StartRedirectChannelToURI(nsIURI *upgradedURI)
// Inform consumers about this fake redirect
mRedirectChannel = newChannel;
uint32_t flags = nsIChannelEventSink::REDIRECT_PERMANENT;
PushRedirectAsyncFunc(
&nsHttpChannel::ContinueAsyncRedirectChannelToURI);
@ -4951,6 +4956,15 @@ nsHttpChannel::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
NS_WARNING("No response head in OnStartRequest");
}
// cache file could be deleted on our behalf, reload from network here.
if (mCacheEntry && mCachePump && CACHE_FILE_GONE(mStatus)) {
LOG((" cache file gone, reloading from server"));
mCacheEntry->AsyncDoom(nullptr);
nsresult rv = StartRedirectChannelToURI(mURI, nsIChannelEventSink::REDIRECT_INTERNAL);
if (NS_SUCCEEDED(rv))
return NS_OK;
}
// avoid crashing if mListener happens to be null...
if (!mListener) {
NS_NOTREACHED("mListener is null");

View File

@ -231,7 +231,7 @@ private:
void HandleAsyncFallback();
nsresult ContinueHandleAsyncFallback(nsresult);
nsresult PromptTempRedirect();
nsresult StartRedirectChannelToURI(nsIURI *);
nsresult StartRedirectChannelToURI(nsIURI *, uint32_t);
virtual nsresult SetupReplacementChannel(nsIURI *, nsIChannel *, bool preserveMethod);
// proxy specific methods