fixes bug 24197 "RFE Show progress while uploading files (in a form post)"

r=dougt sr=rpotts
This commit is contained in:
darin%netscape.com 2002-09-11 03:23:36 +00:00
parent f83410ff28
commit 5b8a53a10d
2 changed files with 20 additions and 2 deletions

View File

@ -88,6 +88,8 @@ nsHttpTransaction::nsHttpTransaction(nsIStreamListener *listener,
: mListener(listener)
, mCallbacks(callbacks)
, mConnection(nsnull)
, mReqUploadStreamOffset(0)
, mReqUploadStreamLength(0)
, mResponseHead(nsnull)
, mContentLength(-1)
, mContentRead(0)
@ -173,6 +175,10 @@ nsHttpTransaction::SetupRequest(nsHttpRequestHead *requestHead,
#endif
mReqUploadStream = requestBody;
if (mReqUploadStream) {
mReqUploadStream->Available(&mReqUploadStreamLength);
mReqUploadStreamOffset = 0;
}
// If the request body does not include headers or if there is no request
// body, then we must add the header/body separator manually.
@ -231,8 +237,17 @@ nsHttpTransaction::OnDataWritable(nsIOutputStream *os)
if (n != 0)
return os->WriteFrom(mReqHeaderStream, NS_HTTP_BUFFER_SIZE, &n);
if (mReqUploadStream)
return os->WriteFrom(mReqUploadStream, NS_HTTP_BUFFER_SIZE, &n);
if (mReqUploadStream) {
nsresult rv = os->WriteFrom(mReqUploadStream, NS_HTTP_BUFFER_SIZE, &n);
if (NS_SUCCEEDED(rv)) {
mReqUploadStreamOffset += n;
if (mProgressSink)
mProgressSink->OnProgress(nsnull, nsnull,
mReqUploadStreamOffset,
mReqUploadStreamLength);
}
return rv;
}
return NS_BASE_STREAM_CLOSED;
}
@ -344,6 +359,7 @@ nsHttpTransaction::Restart()
seekable = do_QueryInterface(mReqUploadStream);
if (seekable)
seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
mReqUploadStreamOffset = 0;
// just in case the connection is holding the last reference to us...
NS_ADDREF_THIS();

View File

@ -118,6 +118,8 @@ private:
nsCString mReqHeaderBuf; // flattened request headers
nsCOMPtr<nsIInputStream> mReqHeaderStream; // header data stream
nsCOMPtr<nsIInputStream> mReqUploadStream; // upload data stream
PRUint32 mReqUploadStreamOffset;
PRUint32 mReqUploadStreamLength;
nsCOMPtr<nsIInputStream> mSource;
nsHttpRequestHead *mRequestHead; // weak ref