diff --git a/netwerk/protocol/data/nsDataChannel.cpp b/netwerk/protocol/data/nsDataChannel.cpp index a2be796076b3..33ad0a9889eb 100644 --- a/netwerk/protocol/data/nsDataChannel.cpp +++ b/netwerk/protocol/data/nsDataChannel.cpp @@ -8,10 +8,12 @@ #include "nsDataChannel.h" #include "mozilla/Base64.h" +#include "nsIOService.h" #include "nsDataHandler.h" +#include "nsIPipe.h" #include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsEscape.h" -#include "nsStringStream.h" using namespace mozilla; @@ -84,6 +86,16 @@ nsDataChannel::OpenContentStream(bool async, nsIInputStream **result, } nsCOMPtr bufInStream; + nsCOMPtr bufOutStream; + + // create an unbounded pipe. + rv = NS_NewPipe(getter_AddRefs(bufInStream), + getter_AddRefs(bufOutStream), + nsIOService::gDefaultSegmentSize, + UINT32_MAX, + async, true); + if (NS_FAILED(rv)) + return rv; uint32_t contentLen; if (lBase64) { @@ -91,11 +103,9 @@ nsDataChannel::OpenContentStream(bool async, nsIInputStream **result, rv = Base64Decode(data, decodedData); NS_ENSURE_SUCCESS(rv, rv); - contentLen = decodedData.Length(); - rv = NS_NewCStringInputStream(getter_AddRefs(bufInStream), decodedData); + rv = bufOutStream->Write(decodedData.get(), decodedData.Length(), &contentLen); } else { - contentLen = data.Length(); - rv = NS_NewCStringInputStream(getter_AddRefs(bufInStream), data); + rv = bufOutStream->Write(data.Data(), data.Length(), &contentLen); } if (NS_FAILED(rv)) diff --git a/xpcom/io/NonBlockingAsyncInputStream.cpp b/xpcom/io/NonBlockingAsyncInputStream.cpp index 854e9826c61e..2e467b46e2ca 100644 --- a/xpcom/io/NonBlockingAsyncInputStream.cpp +++ b/xpcom/io/NonBlockingAsyncInputStream.cpp @@ -169,19 +169,7 @@ NonBlockingAsyncInputStream::Close() NS_IMETHODIMP NonBlockingAsyncInputStream::Available(uint64_t* aLength) { - nsresult rv = mInputStream->Available(aLength); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - // Nothing more to read. Let's close the stream now. - if (*aLength == 0) { - mInputStream->Close(); - mClosed = true; - return NS_BASE_STREAM_CLOSED; - } - - return NS_OK; + return mInputStream->Available(aLength); } NS_IMETHODIMP