зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1487113 - nsHttpChannel should return the Content-Length even when alt-data is available if not delivered, r=valentin
Without this patch, content-length getter returns 0 if we have an available alt-data because we don't distinguish between having and using it. Differential Revision: https://phabricator.services.mozilla.com/D24875 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
b559cdd7d3
Коммит
a8466fb647
|
@ -166,7 +166,7 @@ HttpBaseChannel::HttpBaseChannel()
|
||||||
mRequestContextID(0),
|
mRequestContextID(0),
|
||||||
mContentWindowId(0),
|
mContentWindowId(0),
|
||||||
mTopLevelOuterContentWindowId(0),
|
mTopLevelOuterContentWindowId(0),
|
||||||
mAltDataLength(0),
|
mAltDataLength(-1),
|
||||||
mChannelId(0),
|
mChannelId(0),
|
||||||
mReqContentLength(0U),
|
mReqContentLength(0U),
|
||||||
mStatus(NS_OK),
|
mStatus(NS_OK),
|
||||||
|
@ -221,6 +221,7 @@ HttpBaseChannel::HttpBaseChannel()
|
||||||
mInternalRedirectCount(0),
|
mInternalRedirectCount(0),
|
||||||
mAsyncOpenTimeOverriden(false),
|
mAsyncOpenTimeOverriden(false),
|
||||||
mForcePending(false),
|
mForcePending(false),
|
||||||
|
mDeliveringAltData(false),
|
||||||
mCorsIncludeCredentials(false),
|
mCorsIncludeCredentials(false),
|
||||||
mOnStartRequestCalled(false),
|
mOnStartRequestCalled(false),
|
||||||
mOnStopRequestCalled(false),
|
mOnStopRequestCalled(false),
|
||||||
|
@ -729,7 +730,8 @@ HttpBaseChannel::GetContentLength(int64_t* aContentLength) {
|
||||||
|
|
||||||
if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE;
|
if (!mResponseHead) return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
if (!mAvailableCachedAltDataType.IsEmpty()) {
|
if (mDeliveringAltData) {
|
||||||
|
MOZ_ASSERT(!mAvailableCachedAltDataType.IsEmpty());
|
||||||
*aContentLength = mAltDataLength;
|
*aContentLength = mAltDataLength;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -1192,7 +1194,8 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mAvailableCachedAltDataType.IsEmpty()) {
|
if (mDeliveringAltData) {
|
||||||
|
MOZ_ASSERT(!mAvailableCachedAltDataType.IsEmpty());
|
||||||
LOG(("not applying conversion because delivering alt-data\n"));
|
LOG(("not applying conversion because delivering alt-data\n"));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,6 +403,8 @@ class HttpBaseChannel : public nsHashPropertyBag,
|
||||||
int64_t GetAltDataLength() { return mAltDataLength; }
|
int64_t GetAltDataLength() { return mAltDataLength; }
|
||||||
bool IsNavigation();
|
bool IsNavigation();
|
||||||
|
|
||||||
|
bool IsDeliveringAltData() const { return mDeliveringAltData; }
|
||||||
|
|
||||||
static bool IsReferrerSchemeAllowed(nsIURI *aReferrer);
|
static bool IsReferrerSchemeAllowed(nsIURI *aReferrer);
|
||||||
|
|
||||||
static void PropagateReferenceIfNeeded(nsIURI *aURI,
|
static void PropagateReferenceIfNeeded(nsIURI *aURI,
|
||||||
|
@ -768,6 +770,9 @@ class HttpBaseChannel : public nsHashPropertyBag,
|
||||||
bool mAsyncOpenTimeOverriden;
|
bool mAsyncOpenTimeOverriden;
|
||||||
bool mForcePending;
|
bool mForcePending;
|
||||||
|
|
||||||
|
// true if the channel is deliving alt-data.
|
||||||
|
bool mDeliveringAltData;
|
||||||
|
|
||||||
bool mCorsIncludeCredentials;
|
bool mCorsIncludeCredentials;
|
||||||
|
|
||||||
// These parameters are used to ensure that we do not call OnStartRequest and
|
// These parameters are used to ensure that we do not call OnStartRequest and
|
||||||
|
|
|
@ -405,7 +405,8 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
|
||||||
const nsCString& aSecurityInfoSerialization, const NetAddr& aSelfAddr,
|
const nsCString& aSecurityInfoSerialization, const NetAddr& aSelfAddr,
|
||||||
const NetAddr& aPeerAddr, const uint32_t& aCacheKey,
|
const NetAddr& aPeerAddr, const uint32_t& aCacheKey,
|
||||||
const nsCString& altDataType, const int64_t& altDataLen,
|
const nsCString& altDataType, const int64_t& altDataLen,
|
||||||
const bool& aApplyConversion, const ResourceTimingStruct& aTiming)
|
const bool& deliveringAltData, const bool& aApplyConversion,
|
||||||
|
const ResourceTimingStruct& aTiming)
|
||||||
: NeckoTargetChannelEvent<HttpChannelChild>(aChild),
|
: NeckoTargetChannelEvent<HttpChannelChild>(aChild),
|
||||||
mChannelStatus(aChannelStatus),
|
mChannelStatus(aChannelStatus),
|
||||||
mResponseHead(aResponseHead),
|
mResponseHead(aResponseHead),
|
||||||
|
@ -424,6 +425,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
|
||||||
mCacheKey(aCacheKey),
|
mCacheKey(aCacheKey),
|
||||||
mAltDataType(altDataType),
|
mAltDataType(altDataType),
|
||||||
mAltDataLen(altDataLen),
|
mAltDataLen(altDataLen),
|
||||||
|
mDeliveringAltData(deliveringAltData),
|
||||||
mLoadInfoForwarder(loadInfoForwarder),
|
mLoadInfoForwarder(loadInfoForwarder),
|
||||||
mTiming(aTiming) {}
|
mTiming(aTiming) {}
|
||||||
|
|
||||||
|
@ -434,7 +436,8 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
|
||||||
mLoadInfoForwarder, mIsFromCache, mCacheEntryAvailable, mCacheEntryId,
|
mLoadInfoForwarder, mIsFromCache, mCacheEntryAvailable, mCacheEntryId,
|
||||||
mCacheFetchCount, mCacheExpirationTime, mCachedCharset,
|
mCacheFetchCount, mCacheExpirationTime, mCachedCharset,
|
||||||
mSecurityInfoSerialization, mSelfAddr, mPeerAddr, mCacheKey,
|
mSecurityInfoSerialization, mSelfAddr, mPeerAddr, mCacheKey,
|
||||||
mAltDataType, mAltDataLen, mApplyConversion, mTiming);
|
mAltDataType, mAltDataLen, mDeliveringAltData, mApplyConversion,
|
||||||
|
mTiming);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -455,6 +458,7 @@ class StartRequestEvent : public NeckoTargetChannelEvent<HttpChannelChild> {
|
||||||
uint32_t mCacheKey;
|
uint32_t mCacheKey;
|
||||||
nsCString mAltDataType;
|
nsCString mAltDataType;
|
||||||
int64_t mAltDataLen;
|
int64_t mAltDataLen;
|
||||||
|
bool mDeliveringAltData;
|
||||||
ParentLoadInfoForwarderArgs mLoadInfoForwarder;
|
ParentLoadInfoForwarderArgs mLoadInfoForwarder;
|
||||||
ResourceTimingStruct mTiming;
|
ResourceTimingStruct mTiming;
|
||||||
};
|
};
|
||||||
|
@ -469,8 +473,8 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest(
|
||||||
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
||||||
const NetAddr& peerAddr, const int16_t& redirectCount,
|
const NetAddr& peerAddr, const int16_t& redirectCount,
|
||||||
const uint32_t& cacheKey, const nsCString& altDataType,
|
const uint32_t& cacheKey, const nsCString& altDataType,
|
||||||
const int64_t& altDataLen, const bool& aApplyConversion,
|
const int64_t& altDataLen, const bool& deliveringAltData,
|
||||||
const ResourceTimingStruct& aTiming) {
|
const bool& aApplyConversion, const ResourceTimingStruct& aTiming) {
|
||||||
AUTO_PROFILER_LABEL("HttpChannelChild::RecvOnStartRequest", NETWORK);
|
AUTO_PROFILER_LABEL("HttpChannelChild::RecvOnStartRequest", NETWORK);
|
||||||
LOG(("HttpChannelChild::RecvOnStartRequest [this=%p]\n", this));
|
LOG(("HttpChannelChild::RecvOnStartRequest [this=%p]\n", this));
|
||||||
// mFlushedForDiversion and mDivertingToParent should NEVER be set at this
|
// mFlushedForDiversion and mDivertingToParent should NEVER be set at this
|
||||||
|
@ -489,7 +493,7 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvOnStartRequest(
|
||||||
loadInfoForwarder, isFromCache, cacheEntryAvailable, cacheEntryId,
|
loadInfoForwarder, isFromCache, cacheEntryAvailable, cacheEntryId,
|
||||||
cacheFetchCount, cacheExpirationTime, cachedCharset,
|
cacheFetchCount, cacheExpirationTime, cachedCharset,
|
||||||
securityInfoSerialization, selfAddr, peerAddr, cacheKey, altDataType,
|
securityInfoSerialization, selfAddr, peerAddr, cacheKey, altDataType,
|
||||||
altDataLen, aApplyConversion, aTiming));
|
altDataLen, deliveringAltData, aApplyConversion, aTiming));
|
||||||
|
|
||||||
{
|
{
|
||||||
// Child's mEventQ is to control the execution order of the IPC messages
|
// Child's mEventQ is to control the execution order of the IPC messages
|
||||||
|
@ -522,7 +526,8 @@ void HttpChannelChild::OnStartRequest(
|
||||||
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
||||||
const NetAddr& peerAddr, const uint32_t& cacheKey,
|
const NetAddr& peerAddr, const uint32_t& cacheKey,
|
||||||
const nsCString& altDataType, const int64_t& altDataLen,
|
const nsCString& altDataType, const int64_t& altDataLen,
|
||||||
const bool& aApplyConversion, const ResourceTimingStruct& aTiming) {
|
const bool& deliveringAltData, const bool& aApplyConversion,
|
||||||
|
const ResourceTimingStruct& aTiming) {
|
||||||
LOG(("HttpChannelChild::OnStartRequest [this=%p]\n", this));
|
LOG(("HttpChannelChild::OnStartRequest [this=%p]\n", this));
|
||||||
|
|
||||||
// mFlushedForDiversion and mDivertingToParent should NEVER be set at this
|
// mFlushedForDiversion and mDivertingToParent should NEVER be set at this
|
||||||
|
@ -573,6 +578,7 @@ void HttpChannelChild::OnStartRequest(
|
||||||
mPeerAddr = peerAddr;
|
mPeerAddr = peerAddr;
|
||||||
|
|
||||||
mAvailableCachedAltDataType = altDataType;
|
mAvailableCachedAltDataType = altDataType;
|
||||||
|
mDeliveringAltData = deliveringAltData;
|
||||||
mAltDataLength = altDataLen;
|
mAltDataLength = altDataLen;
|
||||||
|
|
||||||
SetApplyConversion(aApplyConversion);
|
SetApplyConversion(aApplyConversion);
|
||||||
|
|
|
@ -144,7 +144,8 @@ class HttpChannelChild final : public PHttpChannelChild,
|
||||||
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
||||||
const NetAddr& peerAddr, const int16_t& redirectCount,
|
const NetAddr& peerAddr, const int16_t& redirectCount,
|
||||||
const uint32_t& cacheKey, const nsCString& altDataType,
|
const uint32_t& cacheKey, const nsCString& altDataType,
|
||||||
const int64_t& altDataLen, const bool& aApplyConversion,
|
const int64_t& altDataLen, const bool& deliveringAltData,
|
||||||
|
const bool& aApplyConversion,
|
||||||
const ResourceTimingStruct& aTiming) override;
|
const ResourceTimingStruct& aTiming) override;
|
||||||
mozilla::ipc::IPCResult RecvFailedAsyncOpen(const nsresult& status) override;
|
mozilla::ipc::IPCResult RecvFailedAsyncOpen(const nsresult& status) override;
|
||||||
mozilla::ipc::IPCResult RecvRedirect1Begin(
|
mozilla::ipc::IPCResult RecvRedirect1Begin(
|
||||||
|
@ -468,7 +469,8 @@ class HttpChannelChild final : public PHttpChannelChild,
|
||||||
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
const nsCString& securityInfoSerialization, const NetAddr& selfAddr,
|
||||||
const NetAddr& peerAddr, const uint32_t& cacheKey,
|
const NetAddr& peerAddr, const uint32_t& cacheKey,
|
||||||
const nsCString& altDataType, const int64_t& altDataLen,
|
const nsCString& altDataType, const int64_t& altDataLen,
|
||||||
const bool& aApplyConversion, const ResourceTimingStruct& aTiming);
|
const bool& deliveringAltData, const bool& aApplyConversion,
|
||||||
|
const ResourceTimingStruct& aTiming);
|
||||||
void MaybeDivertOnData(const nsCString& data, const uint64_t& offset,
|
void MaybeDivertOnData(const nsCString& data, const uint64_t& offset,
|
||||||
const uint32_t& count);
|
const uint32_t& count);
|
||||||
void OnTransportAndData(const nsresult& channelStatus, const nsresult& status,
|
void OnTransportAndData(const nsresult& channelStatus, const nsresult& status,
|
||||||
|
|
|
@ -1411,6 +1411,7 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
|
||||||
chan->GetRedirectCount(&redirectCount);
|
chan->GetRedirectCount(&redirectCount);
|
||||||
|
|
||||||
int64_t altDataLen = chan->GetAltDataLength();
|
int64_t altDataLen = chan->GetAltDataLength();
|
||||||
|
bool deliveringAltData = chan->IsDeliveringAltData();
|
||||||
|
|
||||||
nsCOMPtr<nsILoadInfo> loadInfo;
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
||||||
Unused << chan->GetLoadInfo(getter_AddRefs(loadInfo));
|
Unused << chan->GetLoadInfo(getter_AddRefs(loadInfo));
|
||||||
|
@ -1455,8 +1456,8 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
|
||||||
loadInfoForwarderArg, isFromCache, mCacheEntry ? true : false,
|
loadInfoForwarderArg, isFromCache, mCacheEntry ? true : false,
|
||||||
cacheEntryId, fetchCount, expirationTime, cachedCharset,
|
cacheEntryId, fetchCount, expirationTime, cachedCharset,
|
||||||
secInfoSerialization, chan->GetSelfAddr(), chan->GetPeerAddr(),
|
secInfoSerialization, chan->GetSelfAddr(), chan->GetPeerAddr(),
|
||||||
redirectCount, cacheKey, altDataType, altDataLen, applyConversion,
|
redirectCount, cacheKey, altDataType, altDataLen, deliveringAltData,
|
||||||
timing)) {
|
applyConversion, timing)) {
|
||||||
rv = NS_ERROR_UNEXPECTED;
|
rv = NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
requestHead->Exit();
|
requestHead->Exit();
|
||||||
|
|
|
@ -124,6 +124,7 @@ child:
|
||||||
uint32_t cacheKey,
|
uint32_t cacheKey,
|
||||||
nsCString altDataType,
|
nsCString altDataType,
|
||||||
int64_t altDataLength,
|
int64_t altDataLength,
|
||||||
|
bool deliveringAltData,
|
||||||
bool applyConversion,
|
bool applyConversion,
|
||||||
ResourceTimingStruct timing);
|
ResourceTimingStruct timing);
|
||||||
|
|
||||||
|
|
|
@ -1090,10 +1090,9 @@ nsresult nsHttpChannel::SetupTransaction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mIgnoreCacheEntry) {
|
if (mIgnoreCacheEntry) {
|
||||||
if (!mAvailableCachedAltDataType.IsEmpty()) {
|
mAvailableCachedAltDataType.Truncate();
|
||||||
mAvailableCachedAltDataType.Truncate();
|
mDeliveringAltData = false;
|
||||||
mAltDataLength = 0;
|
mAltDataLength = -1;
|
||||||
}
|
|
||||||
mCacheInputStream.CloseAndRelease();
|
mCacheInputStream.CloseAndRelease();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4969,12 +4968,14 @@ nsresult nsHttpChannel::OpenCacheInputStream(nsICacheEntry *cacheEntry,
|
||||||
LOG(("Opened alt-data input stream type=%s", altDataType.get()));
|
LOG(("Opened alt-data input stream type=%s", altDataType.get()));
|
||||||
// We have succeeded.
|
// We have succeeded.
|
||||||
mAvailableCachedAltDataType = altDataType;
|
mAvailableCachedAltDataType = altDataType;
|
||||||
|
mDeliveringAltData = deliverAltData;
|
||||||
|
|
||||||
|
// Set the correct data size on the channel.
|
||||||
|
Unused << cacheEntry->GetAltDataSize(&altDataSize);
|
||||||
|
mAltDataLength = altDataSize;
|
||||||
|
|
||||||
if (deliverAltData) {
|
if (deliverAltData) {
|
||||||
// Set the correct data size on the channel.
|
|
||||||
Unused << cacheEntry->GetAltDataSize(&altDataSize);
|
|
||||||
stream = altData;
|
stream = altData;
|
||||||
mAltDataLength = altDataSize;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5296,6 +5297,7 @@ nsresult nsHttpChannel::InitCacheEntry() {
|
||||||
"recreating cache entry\n"));
|
"recreating cache entry\n"));
|
||||||
// clean the altData cache and reset this to avoid wrong content length
|
// clean the altData cache and reset this to avoid wrong content length
|
||||||
mAvailableCachedAltDataType.Truncate();
|
mAvailableCachedAltDataType.Truncate();
|
||||||
|
mDeliveringAltData = false;
|
||||||
|
|
||||||
nsCOMPtr<nsICacheEntry> currentEntry;
|
nsCOMPtr<nsICacheEntry> currentEntry;
|
||||||
currentEntry.swap(mCacheEntry);
|
currentEntry.swap(mCacheEntry);
|
||||||
|
@ -7478,6 +7480,7 @@ nsHttpChannel::OnStartRequest(nsIRequest *request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAvailableCachedAltDataType.Truncate();
|
mAvailableCachedAltDataType.Truncate();
|
||||||
|
mDeliveringAltData = false;
|
||||||
} else if (WRONG_RACING_RESPONSE_SOURCE(request)) {
|
} else if (WRONG_RACING_RESPONSE_SOURCE(request)) {
|
||||||
LOG((" Early return when racing. This response not needed."));
|
LOG((" Early return when racing. This response not needed."));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче