mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 16:28:38 +09:00
Issue #2402 - Move code to fill InternalHeaders from an nsIChannel response into utility method. https://bugzilla.mozilla.org/show_bug.cgi?id=1337543
This commit is contained in:
parent
15875f3d8c
commit
14f0bc5e7c
3 changed files with 45 additions and 38 deletions
|
|
@ -12,7 +12,6 @@
|
|||
#include "nsIOutputStream.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
#include "nsIHttpHeaderVisitor.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIThreadRetargetableRequest.h"
|
||||
#include "nsIUploadChannel2.h"
|
||||
|
|
@ -449,38 +448,6 @@ FetchDriver::FailWithNetworkError()
|
|||
mChannel = nullptr;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -540,11 +507,7 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
|
|||
response = new InternalResponse(responseStatus, statusText,
|
||||
mRequest->GetCredentialsMode());
|
||||
|
||||
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"
|
||||
|
||||
|
|
@ -478,6 +479,48 @@ InternalHeaders::Fill(const Record<nsCString, nsCString>& aInit, ErrorResult& aR
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ public:
|
|||
void Fill(const InternalHeaders& aInit, ErrorResult& aRv);
|
||||
void Fill(const Sequence<Sequence<nsCString>>& aInit, ErrorResult& aRv);
|
||||
void Fill(const Record<nsCString, nsCString>& aInit, ErrorResult& aRv);
|
||||
void FillResponseHeaders(nsIRequest* aRequest);
|
||||
|
||||
bool HasOnlySimpleHeaders() const;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue