Bug 1494176 - nsHttpChannel must clone the upload stream if it doesn't implement ::Seek(), r=mayhemer

This commit is contained in:
Andrea Marchesini 2018-10-03 22:51:55 +02:00
parent 38b412e89d
commit 165f1339fd
3 changed files with 24 additions and 5 deletions

View File

@ -914,9 +914,20 @@ HttpBaseChannel::EnsureUploadStreamIsCloneable(nsIRunnable* aCallback)
// this is called more than once simultaneously.
NS_ENSURE_FALSE(mUploadCloneableCallback, NS_ERROR_UNEXPECTED);
// If the CloneUploadStream() will succeed, then synchronously invoke
// the callback to indicate we're already cloneable.
if (!mUploadStream || NS_InputStreamIsCloneable(mUploadStream)) {
// We can immediately exec the callback if we don't have an upload stream.
if (!mUploadStream) {
aCallback->Run();
return NS_OK;
}
// Some nsSeekableStreams do not implement ::Seek() (see nsPipeInputStream).
// In this case, we must clone the uploadStream into a memory stream in order
// to have it seekable. If the CloneUploadStream() will succeed, then
// synchronously invoke the callback to indicate we're already cloneable.
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mUploadStream);
if (seekable &&
NS_SUCCEEDED(seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0)) &&
NS_InputStreamIsCloneable(mUploadStream)) {
aCallback->Run();
return NS_OK;
}

View File

@ -718,6 +718,15 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
})
->Track(mRequest);
// The stream, received from the child process, must be cloneable and seekable
// in order to allow devtools to inspect its content.
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction("HttpChannelParent::EnsureUploadStreamIsCloneable",
[self]() {
self->TryInvokeAsyncOpen(NS_OK);
});
++mAsyncOpenBarrier;
mChannel->EnsureUploadStreamIsCloneable(r);
return true;
}
@ -741,7 +750,7 @@ HttpChannelParent::WaitForBgParent()
return promise.forget();
}
return mPromise.Ensure(__func__);;
return mPromise.Ensure(__func__);
}
bool

View File

@ -1528,7 +1528,6 @@ nsPipeInputStream::AsyncWait(nsIInputStreamCallback* aCallback,
NS_IMETHODIMP
nsPipeInputStream::Seek(int32_t aWhence, int64_t aOffset)
{
MOZ_ASSERT_UNREACHABLE("nsPipeInputStream::Seek");
return NS_ERROR_NOT_IMPLEMENTED;
}