Bug 1468828 Automatically copy headers to the InterceptedHttpChannel when performing the special hidden internal redirect. r=valentin

This commit is contained in:
Ben Kelly 2018-06-19 11:24:36 -04:00
Родитель 53bab65576
Коммит dea8612c12
1 изменённых файлов: 45 добавлений и 0 удалений

Просмотреть файл

@ -9305,6 +9305,34 @@ nsHttpChannel::GetWarningReporter()
return mWarningReporter.get();
}
namespace {
class CopyNonDefaultHeaderVisitor final : public nsIHttpHeaderVisitor
{
nsCOMPtr<nsIHttpChannel> mTarget;
~CopyNonDefaultHeaderVisitor() = default;
NS_IMETHOD
VisitHeader(const nsACString& aHeader, const nsACString& aValue) override
{
return mTarget->SetRequestHeader(aHeader, aValue, false /* merge */);
}
public:
explicit CopyNonDefaultHeaderVisitor(nsIHttpChannel* aTarget)
: mTarget(aTarget)
{
MOZ_DIAGNOSTIC_ASSERT(mTarget);
}
NS_DECL_ISUPPORTS
};
NS_IMPL_ISUPPORTS(CopyNonDefaultHeaderVisitor, nsIHttpHeaderVisitor)
} // anonymous namespace
nsresult
nsHttpChannel::RedirectToInterceptedChannel()
{
@ -9328,6 +9356,23 @@ nsHttpChannel::RedirectToInterceptedChannel()
nsIChannelEventSink::REDIRECT_INTERNAL);
NS_ENSURE_SUCCESS(rv, rv);
// Some APIs, like fetch(), allow content to set non-standard headers.
// Normally these APIs are responsible for copying these headers across
// redirects. In the e10s parent-side intercept case, though, we currently
// "hide" the internal redirect to the InterceptedHttpChannel. So the
// fetch() API does not have the opportunity to move headers over.
// Therefore, we do it automatically here.
//
// Once child-side interception is removed and the internal redirect no
// longer needs to be "hidden", then this header copying code can be
// removed.
if (ServiceWorkerParentInterceptEnabled()) {
nsCOMPtr<nsIHttpHeaderVisitor> visitor =
new CopyNonDefaultHeaderVisitor(intercepted);
rv = VisitNonDefaultRequestHeaders(visitor);
NS_ENSURE_SUCCESS(rv, rv);
}
mRedirectChannel = intercepted;
PushRedirectAsyncFunc(