Source code
Revision control
Copy as Markdown
Other Tools
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
#ifndef mozilla_net_HttpBaseChannel_h
#define mozilla_net_HttpBaseChannel_h
#include <utility>
#include "OpaqueResponseUtils.h"
#include "mozilla/AtomicBitfields.h"
#include "mozilla/Atomics.h"
#include "mozilla/CompactPair.h"
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/DataMutex.h"
#include <mozilla/Maybe.h>
#include "mozilla/net/DNS.h"
#include "mozilla/net/NeckoChannelParams.h"
#include "mozilla/net/NeckoCommon.h"
#include "mozilla/net/PrivateBrowsingChannel.h"
#include "nsCOMPtr.h"
#include "nsHashPropertyBag.h"
#include "nsHttp.h"
#include "nsHttpHandler.h"
#include "nsHttpRequestHead.h"
#include "nsIClassOfService.h"
#include "nsIClassifiedChannel.h"
#include "nsIConsoleReportCollector.h"
#include "nsIEncodedChannel.h"
#include "nsIForcePendingChannel.h"
#include "nsIFormPOSTActionChannel.h"
#include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h"
#include "nsILoadInfo.h"
#include "nsIResumableChannel.h"
#include "nsIStringEnumerator.h"
#include "nsISupportsPriority.h"
#include "nsIThrottledInputChannel.h"
#include "nsITimedChannel.h"
#include "nsITraceableChannel.h"
#include "nsITransportSecurityInfo.h"
#include "nsIURI.h"
#include "nsIUploadChannel2.h"
#include "nsStringEnumerator.h"
#include "nsStringFwd.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
#define HTTP_BASE_CHANNEL_IID \
{ \
0x9d5cde03, 0xe6e9, 0x4612, { \
0xbf, 0xef, 0xbb, 0x66, 0xf3, 0xbb, 0x74, 0x46 \
} \
}
class nsIProgressEventSink;
class nsISecurityConsoleMessage;
class nsIPrincipal;
namespace mozilla {
namespace dom {
class PerformanceStorage;
class ContentParent;
} // namespace dom
class LogCollector;
namespace net {
extern mozilla::LazyLogModule gHttpLog;
class OpaqueResponseBlocker;
class PreferredAlternativeDataTypeParams;
enum CacheDisposition : uint8_t {
kCacheUnresolved = 0,
kCacheHit = 1,
kCacheHitViaReval = 2,
kCacheMissedViaReval = 3,
kCacheMissed = 4,
kCacheUnknown = 5
};
// These need to be kept in sync with
// "browser.opaqueResponseBlocking.filterFetchResponse"
enum class OpaqueResponseFilterFetch { Never, AllowedByORB, BlockedByORB, All };
/*
* This class is a partial implementation of nsIHttpChannel. It contains code
* shared by nsHttpChannel and HttpChannelChild.
* - Note that this class has nothing to do with nsBaseChannel, which is an
* earlier effort at a base class for channels that somehow never made it all
* the way to the HTTP channel.
*/
class HttpBaseChannel : public nsHashPropertyBag,
public nsIEncodedChannel,
public nsIHttpChannel,
public nsIHttpChannelInternal,
public nsIFormPOSTActionChannel,
public nsIUploadChannel2,
public nsISupportsPriority,
public nsIClassOfService,
public nsIResumableChannel,
public nsITraceableChannel,
public PrivateBrowsingChannel<HttpBaseChannel>,
public nsITimedChannel,
public nsIForcePendingChannel,
public nsIConsoleReportCollector,
public nsIThrottledInputChannel,
public nsIClassifiedChannel {
protected:
virtual ~HttpBaseChannel();
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIUPLOADCHANNEL
NS_DECL_NSIFORMPOSTACTIONCHANNEL
NS_DECL_NSIUPLOADCHANNEL2
NS_DECL_NSITRACEABLECHANNEL
NS_DECL_NSITIMEDCHANNEL
NS_DECL_NSITHROTTLEDINPUTCHANNEL
NS_DECL_NSICLASSIFIEDCHANNEL
NS_DECLARE_STATIC_IID_ACCESSOR(HTTP_BASE_CHANNEL_IID)
HttpBaseChannel();
[[nodiscard]] virtual nsresult Init(nsIURI* aURI, uint32_t aCaps,
nsProxyInfo* aProxyInfo,
uint32_t aProxyResolveFlags,
nsIURI* aProxyURI, uint64_t aChannelId,
ExtContentPolicyType aContentPolicyType,
nsILoadInfo* aLoadInfo);
// nsIRequest
NS_IMETHOD GetName(nsACString& aName) override;
NS_IMETHOD IsPending(bool* aIsPending) override;
NS_IMETHOD GetStatus(nsresult* aStatus) override;
NS_IMETHOD GetLoadGroup(nsILoadGroup** aLoadGroup) override;
NS_IMETHOD SetLoadGroup(nsILoadGroup* aLoadGroup) override;
NS_IMETHOD GetLoadFlags(nsLoadFlags* aLoadFlags) override;
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) override;
NS_IMETHOD GetTRRMode(nsIRequest::TRRMode* aTRRMode) override;
NS_IMETHOD SetTRRMode(nsIRequest::TRRMode aTRRMode) override;
NS_IMETHOD SetDocshellUserAgentOverride();
// nsIChannel
NS_IMETHOD GetOriginalURI(nsIURI** aOriginalURI) override;
NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) override;
NS_IMETHOD GetURI(nsIURI** aURI) override;
NS_IMETHOD GetOwner(nsISupports** aOwner) override;
NS_IMETHOD SetOwner(nsISupports* aOwner) override;
NS_IMETHOD GetLoadInfo(nsILoadInfo** aLoadInfo) override;
NS_IMETHOD SetLoadInfo(nsILoadInfo* aLoadInfo) override;
NS_IMETHOD GetIsDocument(bool* aIsDocument) override;
NS_IMETHOD GetNotificationCallbacks(
nsIInterfaceRequestor** aCallbacks) override;
NS_IMETHOD SetNotificationCallbacks(
nsIInterfaceRequestor* aCallbacks) override;
NS_IMETHOD GetContentType(nsACString& aContentType) override;
NS_IMETHOD SetContentType(const nsACString& aContentType) override;
NS_IMETHOD GetContentCharset(nsACString& aContentCharset) override;
NS_IMETHOD SetContentCharset(const nsACString& aContentCharset) override;
NS_IMETHOD GetContentDisposition(uint32_t* aContentDisposition) override;
NS_IMETHOD SetContentDisposition(uint32_t aContentDisposition) override;
NS_IMETHOD GetContentDispositionFilename(
nsAString& aContentDispositionFilename) override;
NS_IMETHOD SetContentDispositionFilename(
const nsAString& aContentDispositionFilename) override;
NS_IMETHOD GetContentDispositionHeader(
nsACString& aContentDispositionHeader) override;
NS_IMETHOD GetContentLength(int64_t* aContentLength) override;
NS_IMETHOD SetContentLength(int64_t aContentLength) override;
NS_IMETHOD Open(nsIInputStream** aResult) override;
NS_IMETHOD GetBlockAuthPrompt(bool* aValue) override;
NS_IMETHOD SetBlockAuthPrompt(bool aValue) override;
NS_IMETHOD GetCanceled(bool* aCanceled) override;
// nsIEncodedChannel
NS_IMETHOD GetApplyConversion(bool* value) override;
NS_IMETHOD SetApplyConversion(bool value) override;
NS_IMETHOD GetContentEncodings(nsIUTF8StringEnumerator** aEncodings) override;
NS_IMETHOD DoApplyContentConversions(nsIStreamListener* aNextListener,
nsIStreamListener** aNewNextListener,
nsISupports* aCtxt) override;
NS_IMETHOD SetHasContentDecompressed(bool value) override;
NS_IMETHOD GetHasContentDecompressed(bool* value) override;
// HttpBaseChannel::nsIHttpChannel
NS_IMETHOD GetRequestMethod(nsACString& aMethod) override;
NS_IMETHOD SetRequestMethod(const nsACString& aMethod) override;
NS_IMETHOD GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) override;
NS_IMETHOD SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) override;
NS_IMETHOD SetReferrerInfoWithoutClone(
nsIReferrerInfo* aReferrerInfo) override;
NS_IMETHOD GetRequestHeader(const nsACString& aHeader,
nsACString& aValue) override;
NS_IMETHOD SetRequestHeader(const nsACString& aHeader,
const nsACString& aValue, bool aMerge) override;
NS_IMETHOD SetNewReferrerInfo(const nsACString& aUrl,
nsIReferrerInfo::ReferrerPolicyIDL aPolicy,
bool aSendReferrer) override;
NS_IMETHOD SetEmptyRequestHeader(const nsACString& aHeader) override;
NS_IMETHOD VisitRequestHeaders(nsIHttpHeaderVisitor* visitor) override;
NS_IMETHOD VisitNonDefaultRequestHeaders(
nsIHttpHeaderVisitor* visitor) override;
NS_IMETHOD ShouldStripRequestBodyHeader(const nsACString& aMethod,
bool* aResult) override;
NS_IMETHOD GetResponseHeader(const nsACString& header,
nsACString& value) override;
NS_IMETHOD SetResponseHeader(const nsACString& header,
const nsACString& value, bool merge) override;
NS_IMETHOD VisitResponseHeaders(nsIHttpHeaderVisitor* visitor) override;
NS_IMETHOD GetOriginalResponseHeader(const nsACString& aHeader,
nsIHttpHeaderVisitor* aVisitor) override;
NS_IMETHOD VisitOriginalResponseHeaders(
nsIHttpHeaderVisitor* aVisitor) override;
NS_IMETHOD GetAllowSTS(bool* value) override;
NS_IMETHOD SetAllowSTS(bool value) override;
NS_IMETHOD GetRedirectionLimit(uint32_t* value) override;
NS_IMETHOD SetRedirectionLimit(uint32_t value) override;
NS_IMETHOD IsNoStoreResponse(bool* value) override;
NS_IMETHOD IsNoCacheResponse(bool* value) override;
NS_IMETHOD IsPrivateResponse(bool* value) override;
NS_IMETHOD GetResponseStatus(uint32_t* aValue) override;
NS_IMETHOD GetResponseStatusText(nsACString& aValue) override;
NS_IMETHOD GetRequestSucceeded(bool* aValue) override;
NS_IMETHOD RedirectTo(nsIURI* newURI) override;
NS_IMETHOD TransparentRedirectTo(nsIURI* newURI) override;
NS_IMETHOD UpgradeToSecure() override;
NS_IMETHOD GetRequestObserversCalled(bool* aCalled) override;
NS_IMETHOD SetRequestObserversCalled(bool aCalled) override;
NS_IMETHOD GetRequestContextID(uint64_t* aRCID) override;
NS_IMETHOD GetTransferSize(uint64_t* aTransferSize) override;
NS_IMETHOD GetRequestSize(uint64_t* aRequestSize) override;
NS_IMETHOD GetDecodedBodySize(uint64_t* aDecodedBodySize) override;
NS_IMETHOD GetEncodedBodySize(uint64_t* aEncodedBodySize) override;
NS_IMETHOD GetSupportsHTTP3(bool* aSupportsHTTP3) override;
NS_IMETHOD GetHasHTTPSRR(bool* aHasHTTPSRR) override;
NS_IMETHOD SetRequestContextID(uint64_t aRCID) override;
NS_IMETHOD GetIsMainDocumentChannel(bool* aValue) override;
NS_IMETHOD SetIsMainDocumentChannel(bool aValue) override;
NS_IMETHOD GetProtocolVersion(nsACString& aProtocolVersion) override;
NS_IMETHOD GetChannelId(uint64_t* aChannelId) override;
NS_IMETHOD SetChannelId(uint64_t aChannelId) override;
NS_IMETHOD GetTopLevelContentWindowId(uint64_t* aContentWindowId) override;
NS_IMETHOD SetTopLevelContentWindowId(uint64_t aContentWindowId) override;
NS_IMETHOD GetBrowserId(uint64_t* aId) override;
NS_IMETHOD SetBrowserId(uint64_t aId) override;
NS_IMETHOD GetIsProxyUsed(bool* aIsProxyUsed) override;
using nsIClassifiedChannel::IsThirdPartyTrackingResource;
virtual void SetSource(UniquePtr<ProfileChunkedBuffer> aSource) override {
mSource = std::move(aSource);
}
// nsIHttpChannelInternal
NS_IMETHOD GetDocumentURI(nsIURI** aDocumentURI) override;
NS_IMETHOD SetDocumentURI(nsIURI* aDocumentURI) override;
NS_IMETHOD GetRequestVersion(uint32_t* major, uint32_t* minor) override;
NS_IMETHOD GetResponseVersion(uint32_t* major, uint32_t* minor) override;
NS_IMETHOD SetCookie(const nsACString& aCookieHeader) override;
NS_IMETHOD GetThirdPartyFlags(uint32_t* aForce) override;
NS_IMETHOD SetThirdPartyFlags(uint32_t aForce) override;
NS_IMETHOD GetForceAllowThirdPartyCookie(bool* aForce) override;
NS_IMETHOD SetForceAllowThirdPartyCookie(bool aForce) override;
NS_IMETHOD GetChannelIsForDownload(bool* aChannelIsForDownload) override;
NS_IMETHOD SetChannelIsForDownload(bool aChannelIsForDownload) override;
NS_IMETHOD SetCacheKeysRedirectChain(nsTArray<nsCString>* cacheKeys) override;
NS_IMETHOD GetLocalAddress(nsACString& addr) override;
NS_IMETHOD GetLocalPort(int32_t* port) override;
NS_IMETHOD GetRemoteAddress(nsACString& addr) override;
NS_IMETHOD GetRemotePort(int32_t* port) override;
NS_IMETHOD GetOnlyConnect(bool* aOnlyConnect) override;
NS_IMETHOD SetConnectOnly(bool aTlsTunnel) override;
NS_IMETHOD GetAllowSpdy(bool* aAllowSpdy) override;
NS_IMETHOD SetAllowSpdy(bool aAllowSpdy) override;
NS_IMETHOD GetAllowHttp3(bool* aAllowHttp3) override;
NS_IMETHOD SetAllowHttp3(bool aAllowHttp3) override;
NS_IMETHOD GetAllowAltSvc(bool* aAllowAltSvc) override;
NS_IMETHOD SetAllowAltSvc(bool aAllowAltSvc) override;
NS_IMETHOD GetBeConservative(bool* aBeConservative) override;
NS_IMETHOD SetBeConservative(bool aBeConservative) override;
NS_IMETHOD GetBypassProxy(bool* aBypassProxy) override;
NS_IMETHOD SetBypassProxy(bool aBypassProxy) override;
bool BypassProxy();
NS_IMETHOD GetIsTRRServiceChannel(bool* aTRR) override;
NS_IMETHOD SetIsTRRServiceChannel(bool aTRR) override;
NS_IMETHOD GetIsResolvedByTRR(bool* aResolvedByTRR) override;
NS_IMETHOD GetEffectiveTRRMode(
nsIRequest::TRRMode* aEffectiveTRRMode) override;
NS_IMETHOD GetTrrSkipReason(nsITRRSkipReason::value* aTrrSkipReason) override;
NS_IMETHOD GetIsLoadedBySocketProcess(bool* aResult) override;
NS_IMETHOD GetIsOCSP(bool* value) override;
NS_IMETHOD SetIsOCSP(bool value) override;
NS_IMETHOD GetTlsFlags(uint32_t* aTlsFlags) override;
NS_IMETHOD SetTlsFlags(uint32_t aTlsFlags) override;
NS_IMETHOD GetApiRedirectToURI(nsIURI** aApiRedirectToURI) override;
[[nodiscard]] virtual nsresult AddSecurityMessage(
const nsAString& aMessageTag, const nsAString& aMessageCategory);
NS_IMETHOD TakeAllSecurityMessages(
nsCOMArray<nsISecurityConsoleMessage>& aMessages) override;
NS_IMETHOD GetResponseTimeoutEnabled(bool* aEnable) override;
NS_IMETHOD SetResponseTimeoutEnabled(bool aEnable) override;
NS_IMETHOD GetInitialRwin(uint32_t* aRwin) override;
NS_IMETHOD SetInitialRwin(uint32_t aRwin) override;
NS_IMETHOD ForcePending(bool aForcePending) override;
NS_IMETHOD GetLastModifiedTime(PRTime* lastModifiedTime) override;
NS_IMETHOD GetCorsIncludeCredentials(bool* aInclude) override;
NS_IMETHOD SetCorsIncludeCredentials(bool aInclude) override;
NS_IMETHOD GetRequestMode(dom::RequestMode* aRequestMode) override;
NS_IMETHOD SetRequestMode(dom::RequestMode aRequestMode) override;
NS_IMETHOD GetRedirectMode(uint32_t* aRedirectMode) override;
NS_IMETHOD SetRedirectMode(uint32_t aRedirectMode) override;
NS_IMETHOD GetFetchCacheMode(uint32_t* aFetchCacheMode) override;
NS_IMETHOD SetFetchCacheMode(uint32_t aFetchCacheMode) override;
NS_IMETHOD GetTopWindowURI(nsIURI** aTopWindowURI) override;
NS_IMETHOD SetTopWindowURIIfUnknown(nsIURI* aTopWindowURI) override;
NS_IMETHOD GetProxyURI(nsIURI** proxyURI) override;
virtual void SetCorsPreflightParameters(
const nsTArray<nsCString>& unsafeHeaders,
bool aShouldStripRequestBodyHeader, bool aShouldStripAuthHeader) override;
virtual void SetAltDataForChild(bool aIsForChild) override;
virtual void DisableAltDataCache() override {
StoreDisableAltDataCache(true);
};
NS_IMETHOD GetConnectionInfoHashKey(
nsACString& aConnectionInfoHashKey) override;
NS_IMETHOD GetIntegrityMetadata(nsAString& aIntegrityMetadata) override;
NS_IMETHOD SetIntegrityMetadata(const nsAString& aIntegrityMetadata) override;
NS_IMETHOD GetLastRedirectFlags(uint32_t* aValue) override;
NS_IMETHOD SetLastRedirectFlags(uint32_t aValue) override;
NS_IMETHOD GetNavigationStartTimeStamp(TimeStamp* aTimeStamp) override;
NS_IMETHOD SetNavigationStartTimeStamp(TimeStamp aTimeStamp) override;
NS_IMETHOD CancelByURLClassifier(nsresult aErrorCode) override;
NS_IMETHOD SetIPv4Disabled(void) override;
NS_IMETHOD SetIPv6Disabled(void) override;
NS_IMETHOD GetCrossOriginOpenerPolicy(
nsILoadInfo::CrossOriginOpenerPolicy* aCrossOriginOpenerPolicy) override;
NS_IMETHOD ComputeCrossOriginOpenerPolicy(
nsILoadInfo::CrossOriginOpenerPolicy aInitiatorPolicy,
nsILoadInfo::CrossOriginOpenerPolicy* aOutPolicy) override;
NS_IMETHOD HasCrossOriginOpenerPolicyMismatch(bool* aIsMismatch) override;
NS_IMETHOD GetResponseEmbedderPolicy(
bool aIsOriginTrialCoepCredentiallessEnabled,
nsILoadInfo::CrossOriginEmbedderPolicy* aOutPolicy) override;
inline void CleanRedirectCacheChainIfNecessary() {
auto redirectedCachekeys = mRedirectedCachekeys.Lock();
redirectedCachekeys.ref() = nullptr;
}
NS_IMETHOD HTTPUpgrade(const nsACString& aProtocolName,
nsIHttpUpgradeListener* aListener) override;
void DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() override;
NS_IMETHOD SetEarlyHintPreloaderId(uint64_t aEarlyHintPreloaderId) override;
NS_IMETHOD GetEarlyHintPreloaderId(uint64_t* aEarlyHintPreloaderId) override;
NS_IMETHOD SetEarlyHintLinkType(uint32_t aEarlyHintLinkType) override;
NS_IMETHOD GetEarlyHintLinkType(uint32_t* aEarlyHintLinkType) override;
NS_IMETHOD SetIsUserAgentHeaderModified(bool value) override;
NS_IMETHOD GetIsUserAgentHeaderModified(bool* value) override;
NS_IMETHOD GetLastTransportStatus(nsresult* aLastTransportStatus) override;
NS_IMETHOD GetCaps(uint32_t* aCaps) override {
if (!aCaps) {
return NS_ERROR_INVALID_ARG;
}
*aCaps = mCaps;
return NS_OK;
}
NS_IMETHOD SetClassicScriptHintCharset(
const nsAString& aClassicScriptHintCharset) override;
NS_IMETHOD GetClassicScriptHintCharset(
nsAString& aClassicScriptHintCharset) override;
NS_IMETHOD SetDocumentCharacterSet(
const nsAString& aDocumentCharacterSet) override;
NS_IMETHOD GetDocumentCharacterSet(nsAString& aDocumentCharacterSet) override;
virtual void SetConnectionInfo(
mozilla::net::nsHttpConnectionInfo* aCI) override;
// nsISupportsPriority
NS_IMETHOD GetPriority(int32_t* value) override;
NS_IMETHOD AdjustPriority(int32_t delta) override;
// nsIClassOfService
NS_IMETHOD GetClassFlags(uint32_t* outFlags) override {
*outFlags = mClassOfService.Flags();
return NS_OK;
}
NS_IMETHOD GetIncremental(bool* outIncremental) override {
*outIncremental = mClassOfService.Incremental();
return NS_OK;
}
NS_IMETHOD GetFetchPriority(
nsIClassOfService::FetchPriority* aFetchPriority) override {
*aFetchPriority = mClassOfService.FetchPriority();
return NS_OK;
}
NS_IMETHOD SetFetchPriority(
nsIClassOfService::FetchPriority aFetchPriority) override {
mClassOfService.SetFetchPriority(aFetchPriority);
return NS_OK;
}
void SetFetchPriorityDOM(mozilla::dom::FetchPriority aPriority) override;
// nsIResumableChannel
NS_IMETHOD GetEntityID(nsACString& aEntityID) override;
// nsIConsoleReportCollector
void AddConsoleReport(uint32_t aErrorFlags, const nsACString& aCategory,
nsContentUtils::PropertiesFile aPropertiesFile,
const nsACString& aSourceFileURI, uint32_t aLineNumber,
uint32_t aColumnNumber, const nsACString& aMessageName,
const nsTArray<nsString>& aStringParams) override;
void FlushReportsToConsole(
uint64_t aInnerWindowID,
ReportAction aAction = ReportAction::Forget) override;
void FlushReportsToConsoleForServiceWorkerScope(
const nsACString& aScope,
ReportAction aAction = ReportAction::Forget) override;
void FlushConsoleReports(
dom::Document* aDocument,
ReportAction aAction = ReportAction::Forget) override;
void FlushConsoleReports(
nsILoadGroup* aLoadGroup,
ReportAction aAction = ReportAction::Forget) override;
void FlushConsoleReports(nsIConsoleReportCollector* aCollector) override;
void StealConsoleReports(
nsTArray<net::ConsoleReportCollected>& aReports) override;
void ClearConsoleReports() override;
class nsContentEncodings : public nsStringEnumeratorBase {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIUTF8STRINGENUMERATOR
using nsStringEnumeratorBase::GetNext;
nsContentEncodings(nsIHttpChannel* aChannel, const char* aEncodingHeader);
private:
virtual ~nsContentEncodings() = default;
[[nodiscard]] nsresult PrepareForNext(void);
// We do not own the buffer. The channel owns it.
const char* mEncodingHeader;
const char* mCurStart; // points to start of current header
const char* mCurEnd; // points to end of current header
// Hold a ref to our channel so that it can't go away and take the
// header with it.
nsCOMPtr<nsIHttpChannel> mChannel;
bool mReady;
};
nsHttpResponseHead* GetResponseHead() const { return mResponseHead.get(); }
nsHttpRequestHead* GetRequestHead() { return &mRequestHead; }
nsHttpHeaderArray* GetResponseTrailers() const {
return mResponseTrailers.get();
}
// Return the cloned HTTP Headers if available.
// The returned headers can be passed to SetDummyChannelForCachedResource
// to create a dummy channel with the same HTTP headers.
UniquePtr<nsHttpResponseHead> MaybeCloneResponseHeadForCachedResource();
// Set this channel as a dummy channel for cached resources.
//
// If aMaybeResponseHead is provided, this uses the given HTTP headers.
// Otherwise this uses an empty HTTP headers.
void SetDummyChannelForCachedResource(
const nsHttpResponseHead* aMaybeResponseHead = nullptr);
const NetAddr& GetSelfAddr() { return mSelfAddr; }
const NetAddr& GetPeerAddr() { return mPeerAddr; }
[[nodiscard]] nsresult OverrideSecurityInfo(
nsITransportSecurityInfo* aSecurityInfo);
void LogORBError(const nsAString& aReason,
const OpaqueResponseBlockedTelemetryReason aTelemetryReason);
public: /* Necko internal use only... */
int64_t GetAltDataLength() { return mAltDataLength; }
bool IsNavigation();
bool IsDeliveringAltData() const { return LoadDeliveringAltData(); }
static void PropagateReferenceIfNeeded(nsIURI* aURI,
nsCOMPtr<nsIURI>& aRedirectURI);
// Return whether upon a redirect code of httpStatus for method, the
// request method should be rewritten to GET.
static bool ShouldRewriteRedirectToGET(
uint32_t httpStatus, nsHttpRequestHead::ParsedMethodType method);
// Like nsIEncodedChannel::DoApplyConversions except context is set to
// mListenerContext.
[[nodiscard]] nsresult DoApplyContentConversions(
nsIStreamListener* aNextListener, nsIStreamListener** aNewNextListener);
void AddClassificationFlags(uint32_t aClassificationFlags,
bool aIsThirdParty);
const uint64_t& ChannelId() const { return mChannelId; }
nsresult InternalSetUploadStream(nsIInputStream* uploadStream,
int64_t aContentLength = -1,
bool aSetContentLengthHeader = false);
void SetUploadStreamHasHeaders(bool hasHeaders) {
StoreUploadStreamHasHeaders(hasHeaders);
}
virtual nsresult SetReferrerHeader(const nsACString& aReferrer,
bool aRespectBeforeConnect = true) {
if (aRespectBeforeConnect) {
ENSURE_CALLED_BEFORE_CONNECT();
}
return mRequestHead.SetHeader(nsHttp::Referer, aReferrer);
}
nsresult ClearReferrerHeader() {
ENSURE_CALLED_BEFORE_CONNECT();
return mRequestHead.ClearHeader(nsHttp::Referer);
}
void SetTopWindowURI(nsIURI* aTopWindowURI) { mTopWindowURI = aTopWindowURI; }
// Set referrerInfo and compute the referrer header if neccessary.
// Pass true for aSetOriginal if this is a new referrer and should
// overwrite the 'original' value, false if this is a mutation (like
// stripping the path).
nsresult SetReferrerInfoInternal(nsIReferrerInfo* aReferrerInfo, bool aClone,
bool aCompute, bool aRespectBeforeConnect);
struct ReplacementChannelConfig {
ReplacementChannelConfig() = default;
explicit ReplacementChannelConfig(
const dom::ReplacementChannelConfigInit& aInit);
uint32_t redirectFlags = 0;
ClassOfService classOfService = {0, false};
Maybe<bool> privateBrowsing = Nothing();
Maybe<nsCString> method;
nsCOMPtr<nsIReferrerInfo> referrerInfo;
Maybe<dom::TimedChannelInfo> timedChannelInfo;
nsCOMPtr<nsIInputStream> uploadStream;
uint64_t uploadStreamLength = 0;
bool uploadStreamHasHeaders = false;
Maybe<nsCString> contentType;
Maybe<nsCString> contentLength;
dom::ReplacementChannelConfigInit Serialize();
};
enum class ReplacementReason {
Redirect,
InternalRedirect,
DocumentChannel,
};
// Create a ReplacementChannelConfig object that can be used to duplicate the
// current channel.
ReplacementChannelConfig CloneReplacementChannelConfig(
bool aPreserveMethod, uint32_t aRedirectFlags, ReplacementReason aReason);
static void ConfigureReplacementChannel(nsIChannel*,
const ReplacementChannelConfig&,
ReplacementReason);
// Called before we create the redirect target channel.
already_AddRefed<nsILoadInfo> CloneLoadInfoForRedirect(
nsIURI* aNewURI, uint32_t aRedirectFlags);
// True if we've already applied content conversion to the data
// passed to mListener.
bool HasAppliedConversion() { return LoadHasAppliedConversion(); }
bool HasRedirectTaintedOrigin() { return LoadTaintedOriginFlag(); }
bool ChannelBlockedByOpaqueResponse() const {
return mChannelBlockedByOpaqueResponse;
}
bool CachedOpaqueResponseBlockingPref() const {
return mCachedOpaqueResponseBlockingPref;
}
TimeStamp GetOnStartRequestStartTime() const {