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

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