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:
Brian Smith 2024-01-05 00:57:40 -06:00 committed by roytam1
commit 14f0bc5e7c
3 changed files with 45 additions and 38 deletions

View file

@ -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
{