Bug 1421094 - nsIUploadChannel2.cloneUploadStream returns the length of the stream, r=smaug

This commit is contained in:
Andrea Marchesini 2017-12-12 18:38:19 -06:00
Родитель da0a8f053e
Коммит 5f1be317f0
3 изменённых файлов: 17 добавлений и 4 удалений

Просмотреть файл

@ -1335,6 +1335,7 @@ class FetchEventRunnable : public ExtendableFunctionalEventWorkerRunnable
RequestCredentials mRequestCredentials;
nsContentPolicyType mContentPolicyType;
nsCOMPtr<nsIInputStream> mUploadStream;
int64_t mUploadStreamContentLength;
nsCString mReferrer;
ReferrerPolicy mReferrerPolicy;
nsString mIntegrity;
@ -1363,6 +1364,7 @@ public:
// send credentials to same-origin websites unless explicitly forbidden.
, mRequestCredentials(RequestCredentials::Same_origin)
, mContentPolicyType(nsIContentPolicy::TYPE_INVALID)
, mUploadStreamContentLength(-1)
, mReferrer(kFETCH_CLIENT_REFERRER_STR)
, mReferrerPolicy(ReferrerPolicy::_empty)
{
@ -1496,7 +1498,8 @@ public:
if (uploadChannel) {
MOZ_ASSERT(!mUploadStream);
nsCOMPtr<nsIInputStream> uploadStream;
rv = uploadChannel->CloneUploadStream(getter_AddRefs(uploadStream));
rv = uploadChannel->CloneUploadStream(&mUploadStreamContentLength,
getter_AddRefs(uploadStream));
NS_ENSURE_SUCCESS(rv, rv);
mUploadStream = uploadStream;
}
@ -1606,7 +1609,7 @@ private:
mReferrerPolicy,
mContentPolicyType,
mIntegrity);
internalReq->SetBody(mUploadStream, -1);
internalReq->SetBody(mUploadStream, mUploadStreamContentLength);
// For Telemetry, note that this Request object was created by a Fetch event.
internalReq->SetCreatedByFetchEvent();

Просмотреть файл

@ -61,7 +61,9 @@ interface nsIUploadChannel2 : nsISupports
* Clones the upload stream. May return failure if the upload stream
* is not cloneable. If this is not acceptable, use the
* ensureUploadStreamIsCloneable() method first.
* aContentLength could be -1 in case the size of the stream is unknown,
* otherwise it will contain the known size of the stream.
*/
[noscript]
nsIInputStream cloneUploadStream();
nsIInputStream cloneUploadStream(out long long aContentLength);
};

Просмотреть файл

@ -995,8 +995,10 @@ HttpBaseChannel::EnsureUploadStreamIsCloneableComplete(nsresult aStatus)
}
NS_IMETHODIMP
HttpBaseChannel::CloneUploadStream(nsIInputStream** aClonedStream)
HttpBaseChannel::CloneUploadStream(int64_t* aContentLength,
nsIInputStream** aClonedStream)
{
NS_ENSURE_ARG_POINTER(aContentLength);
NS_ENSURE_ARG_POINTER(aClonedStream);
*aClonedStream = nullptr;
@ -1010,6 +1012,12 @@ HttpBaseChannel::CloneUploadStream(nsIInputStream** aClonedStream)
clonedStream.forget(aClonedStream);
if (mReqContentLengthDetermined) {
*aContentLength = mReqContentLength;
} else {
*aContentLength = -1;
}
return NS_OK;
}