зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337543 P5 Move code to fill InternalHeaders from an nsIChannel response into utility method. r=baku
This commit is contained in:
Родитель
7a88545b94
Коммит
7529d95c7c
|
@ -13,7 +13,6 @@
|
|||
#include "nsIOutputStream.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
#include "nsIHttpHeaderVisitor.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIThreadRetargetableRequest.h"
|
||||
#include "nsIUploadChannel2.h"
|
||||
|
@ -416,38 +415,6 @@ FetchDriver::FailWithNetworkError()
|
|||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
class FillResponseHeaders final : public nsIHttpHeaderVisitor {
|
||||
InternalResponse* mResponse;
|
||||
|
||||
~FillResponseHeaders()
|
||||
{ }
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
explicit FillResponseHeaders(InternalResponse* aResponse)
|
||||
: mResponse(aResponse)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
VisitHeader(const nsACString & aHeader, const nsACString & aValue) override
|
||||
{
|
||||
ErrorResult result;
|
||||
mResponse->Headers()->Append(aHeader, aValue, result);
|
||||
if (result.Failed()) {
|
||||
NS_WARNING(nsPrintfCString("Fetch ignoring illegal header - '%s': '%s'",
|
||||
PromiseFlatCString(aHeader).get(),
|
||||
PromiseFlatCString(aValue).get()).get());
|
||||
result.SuppressException();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(FillResponseHeaders, nsIHttpHeaderVisitor)
|
||||
} // namespace
|
||||
|
||||
NS_IMETHODIMP
|
||||
FetchDriver::OnStartRequest(nsIRequest* aRequest,
|
||||
nsISupports* aContext)
|
||||
|
@ -501,11 +468,7 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
|
|||
|
||||
response = new InternalResponse(responseStatus, statusText);
|
||||
|
||||
RefPtr<FillResponseHeaders> visitor = new FillResponseHeaders(response);
|
||||
rv = httpChannel->VisitResponseHeaders(visitor);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
NS_WARNING("Failed to visit all headers.");
|
||||
}
|
||||
response->Headers()->FillResponseHeaders(httpChannel);
|
||||
|
||||
// If Content-Encoding or Transfer-Encoding headers are set, then the actual
|
||||
// Content-Length (which refer to the decoded data) is obscured behind the encodings.
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIHttpHeaderVisitor.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
|
@ -314,6 +315,48 @@ InternalHeaders::Fill(const MozMap<nsCString>& aInit, ErrorResult& aRv)
|
|||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class FillHeaders final : public nsIHttpHeaderVisitor
|
||||
{
|
||||
RefPtr<InternalHeaders> mInternalHeaders;
|
||||
|
||||
~FillHeaders() = default;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
explicit FillHeaders(InternalHeaders* aInternalHeaders)
|
||||
: mInternalHeaders(aInternalHeaders)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mInternalHeaders);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
VisitHeader(const nsACString& aHeader, const nsACString& aValue) override
|
||||
{
|
||||
IgnoredErrorResult result;
|
||||
mInternalHeaders->Append(aHeader, aValue, result);
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(FillHeaders, nsIHttpHeaderVisitor)
|
||||
|
||||
} // namespace
|
||||
|
||||
void
|
||||
InternalHeaders::FillResponseHeaders(nsIRequest* aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aRequest);
|
||||
if (!httpChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<FillHeaders> visitor = new FillHeaders(this);
|
||||
httpChannel->VisitResponseHeaders(visitor);
|
||||
}
|
||||
|
||||
bool
|
||||
InternalHeaders::HasOnlySimpleHeaders() const
|
||||
{
|
||||
|
|
|
@ -102,6 +102,7 @@ public:
|
|||
void Fill(const InternalHeaders& aInit, ErrorResult& aRv);
|
||||
void Fill(const Sequence<Sequence<nsCString>>& aInit, ErrorResult& aRv);
|
||||
void Fill(const MozMap<nsCString>& aInit, ErrorResult& aRv);
|
||||
void FillResponseHeaders(nsIRequest* aRequest);
|
||||
|
||||
bool HasOnlySimpleHeaders() const;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче