Bug 1172884 P1 Properly decode body when intercepted response redirects. r=jduell

This commit is contained in:
Ben Kelly 2015-06-11 18:29:28 -07:00
parent 734f1f54fe
commit 9e311feb1c
3 changed files with 20 additions and 4 deletions

View File

@ -44,6 +44,9 @@ using namespace mozilla::ipc;
namespace mozilla {
namespace net {
extern bool
WillRedirect(const nsHttpResponseHead * response);
namespace {
const uint32_t kMaxFileDescriptorsPerMessage = 250;
@ -2186,8 +2189,11 @@ HttpChannelChild::OverrideWithSynthesizedResponse(nsAutoPtr<nsHttpResponseHead>&
nsIInputStream* aSynthesizedInput,
nsIStreamListener* aStreamListener)
{
// Intercepted responses should already be decoded.
SetApplyConversion(false);
// Intercepted responses should already be decoded. If its a redirect,
// however, we want to respect the encoding of the final result instead.
if (!WillRedirect(aResponseHead)) {
SetApplyConversion(false);
}
mResponseHead = aResponseHead;
mSynthesizedResponse = true;

View File

@ -18,6 +18,9 @@
namespace mozilla {
namespace net {
extern bool
WillRedirect(const nsHttpResponseHead * response);
extern nsresult
DoAddCacheEntryHeaders(nsHttpChannel *self,
nsICacheEntry *entry,
@ -184,6 +187,13 @@ InterceptedChannelChrome::FinishSynthesizedResponse()
EnsureSynthesizedResponse();
// If the synthesized response is a redirect, then we want to respect
// the encoding of whatever is loaded as a result.
if (WillRedirect(mSynthesizedResponseHead.ref())) {
nsresult rv = mChannel->SetApplyConversion(mOldApplyConversion);
NS_ENSURE_SUCCESS(rv, rv);
}
mChannel->MarkIntercepted();
// First we ensure the appropriate metadata is set on the synthesized cache entry

View File

@ -157,6 +157,8 @@ bool IsRedirectStatus(uint32_t status)
status == 307 || status == 308;
}
} // unnamed namespace
// We only treat 3xx responses as redirects if they have a Location header and
// the status code is in a whitelist.
bool
@ -166,8 +168,6 @@ WillRedirect(const nsHttpResponseHead * response)
response->PeekHeader(nsHttp::Location);
}
} // unnamed namespace
nsresult
StoreAuthorizationMetaData(nsICacheEntry *entry, nsHttpRequestHead *requestHead);