mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1134325 - Part 1: Add an API for cloning a channel's upload stream; r=mcmanus
This commit is contained in:
parent
1883dfa3a7
commit
cfdf005ad6
@ -7,7 +7,7 @@
|
||||
|
||||
interface nsIInputStream;
|
||||
|
||||
[scriptable, uuid(AD9D3F1C-A8DE-4d0b-9714-1B922297AD65)]
|
||||
[scriptable, uuid(62e6529a-5cf6-491a-82ef-b3a8273cdd19)]
|
||||
interface nsIUploadChannel2 : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -45,4 +45,10 @@ interface nsIUploadChannel2 : nsISupports
|
||||
* contians request headers.
|
||||
*/
|
||||
readonly attribute boolean uploadStreamHasHeaders;
|
||||
|
||||
/**
|
||||
* Clones the upload stream and returns an equivalent stream.
|
||||
*/
|
||||
[noscript]
|
||||
nsIInputStream cloneUploadStream();
|
||||
};
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "nsPerformance.h"
|
||||
#include "nsINetworkInterceptController.h"
|
||||
#include "mozIThirdPartyUtil.h"
|
||||
#include "nsStreamUtils.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -564,6 +565,51 @@ HttpBaseChannel::SetUploadStream(nsIInputStream *stream,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
EnsureStreamBuffered(nsCOMPtr<nsIInputStream>& aStream)
|
||||
{
|
||||
if (!NS_InputStreamIsBuffered(aStream)) {
|
||||
nsCOMPtr<nsIInputStream> bufferedStream;
|
||||
nsresult rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
|
||||
aStream,
|
||||
4096);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
aStream.swap(bufferedStream);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HttpBaseChannel::CloneUploadStream(nsIInputStream** aClonedStream)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aClonedStream);
|
||||
*aClonedStream = nullptr;
|
||||
|
||||
if (!mUploadStream) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> clonedStream;
|
||||
nsCOMPtr<nsIInputStream> replacementStream;
|
||||
nsresult rv = NS_CloneInputStream(mUploadStream, getter_AddRefs(clonedStream),
|
||||
getter_AddRefs(replacementStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (replacementStream) {
|
||||
mUploadStream.swap(replacementStream);
|
||||
|
||||
// Ensure that the replacement stream is buffered.
|
||||
EnsureStreamBuffered(mUploadStream);
|
||||
}
|
||||
|
||||
// Ensure that the cloned stream is buffered.
|
||||
EnsureStreamBuffered(clonedStream);
|
||||
|
||||
clonedStream.forget(aClonedStream);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HttpBaseChannel::nsIUploadChannel2
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user