Bug 1188387 - On failure of nsHttpChannel::ProcessNotModified redirect to reload from network, r=michal

--HG--
extra : rebase_source : f714c545a6a1b7fba0691ee5032257f291a558be
This commit is contained in:
Honza Bambas 2016-06-08 04:24:00 +02:00
parent 3dd770634a
commit e7758d8a8c
2 changed files with 44 additions and 15 deletions

View File

@ -1815,14 +1815,32 @@ nsHttpChannel::ContinueProcessResponse1(nsresult rv)
}
break;
case 304:
rv = ProcessNotModified();
if (NS_FAILED(rv)) {
if (!ShouldBypassProcessNotModified()) {
rv = ProcessNotModified();
if (NS_SUCCEEDED(rv)) {
successfulReval = true;
break;
}
LOG(("ProcessNotModified failed [rv=%x]\n", rv));
// We cannot read from the cache entry, it might be in an
// incosistent state. Doom it and redirect the channel
// to the same URI to reload from the network.
mCacheInputStream.CloseAndRelease();
rv = ProcessNormal();
if (mCacheEntry) {
mCacheEntry->AsyncDoom(nullptr);
mCacheEntry = nullptr;
}
rv = StartRedirectChannelToURI(mURI, nsIChannelEventSink::REDIRECT_INTERNAL);
if (NS_SUCCEEDED(rv)) {
return NS_OK;
}
}
else {
successfulReval = true;
if (ShouldBypassProcessNotModified() || NS_FAILED(rv)) {
rv = ProcessNormal();
}
break;
case 401:
@ -2821,6 +2839,23 @@ nsHttpChannel::OnDoneReadingPartialCacheEntry(bool *streamDone)
// nsHttpChannel <cache>
//-----------------------------------------------------------------------------
bool
nsHttpChannel::ShouldBypassProcessNotModified()
{
if (mCustomConditionalRequest) {
LOG(("Bypassing ProcessNotModified due to custom conditional headers"));
return true;
}
if (!mDidReval) {
LOG(("Server returned a 304 response even though we did not send a "
"conditional request"));
return true;
}
return false;
}
nsresult
nsHttpChannel::ProcessNotModified()
{
@ -2828,16 +2863,9 @@ nsHttpChannel::ProcessNotModified()
LOG(("nsHttpChannel::ProcessNotModified [this=%p]\n", this));
if (mCustomConditionalRequest) {
LOG(("Bypassing ProcessNotModified due to custom conditional headers"));
return NS_ERROR_FAILURE;
}
if (!mDidReval) {
LOG(("Server returned a 304 response even though we did not send a "
"conditional request"));
return NS_ERROR_FAILURE;
}
// Assert ShouldBypassProcessNotModified() has been checked before call to
// ProcessNotModified().
MOZ_ASSERT(!ShouldBypassProcessNotModified());
MOZ_ASSERT(mCachedResponseHead);
MOZ_ASSERT(mCacheEntry);

View File

@ -279,6 +279,7 @@ private:
nsresult ProcessNormal();
nsresult ContinueProcessNormal(nsresult);
void ProcessAltService();
bool ShouldBypassProcessNotModified();
nsresult ProcessNotModified();
nsresult AsyncProcessRedirection(uint32_t httpStatus);
nsresult ContinueProcessRedirection(nsresult);