diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp index 249ab518997..c759168e0f5 100644 --- a/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mailnews/base/util/nsMsgDBFolder.cpp @@ -539,11 +539,7 @@ NS_IMETHODIMP nsMsgDBFolder::GetOfflineFileTransport(nsMsgKey msgKey, PRUint32 * if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(localStore, - PR_RDWR | PR_CREATE_FILE, - 0664, - PR_TRUE, - aFileChannel); + rv = fts->CreateTransport(localStore, PR_RDWR | PR_CREATE_FILE, 0664, aFileChannel); if (NS_SUCCEEDED(rv)) { diff --git a/mailnews/base/util/nsMsgProtocol.cpp b/mailnews/base/util/nsMsgProtocol.cpp index a35b4f2bda0..a50f3b894f4 100644 --- a/mailnews/base/util/nsMsgProtocol.cpp +++ b/mailnews/base/util/nsMsgProtocol.cpp @@ -234,7 +234,7 @@ nsresult nsMsgProtocol::OpenFileSocket(nsIURI * aURL, PRUint32 aStartPosition, P if (NS_FAILED(rv)) return rv; //we are always using this file socket to read data from the mailbox. rv = fts->CreateTransport(file, PR_RDONLY, - 0664, PR_TRUE, getter_AddRefs(m_transport)); + 0664, getter_AddRefs(m_transport)); m_socketIsOpen = PR_FALSE; return rv; @@ -880,7 +880,7 @@ nsresult nsMsgFilePostHelper::Init(nsIOutputStream * aOutStream, nsMsgAsyncWrite if (NS_FAILED(rv)) return rv; nsCOMPtr transport; - rv = fts->CreateTransport(aFileToPost, PR_RDONLY, 0664, PR_TRUE, getter_AddRefs(transport)); + rv = fts->CreateTransport(aFileToPost, PR_RDONLY, 0664, getter_AddRefs(transport)); if (transport) { rv = transport->AsyncRead(this, nsnull, 0, PRUint32(-1), 0, getter_AddRefs(mPostFileRequest)); diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index 3e843fc80c9..1f208ffbea8 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -339,7 +339,7 @@ nsJARChannel::AsyncReadJARElement() if (NS_FAILED(rv)) return rv; nsCOMPtr jarTransport; - rv = fts->CreateTransportFromStreamIO(this, PR_TRUE, getter_AddRefs(jarTransport)); + rv = fts->CreateTransportFromStreamIO(this, getter_AddRefs(jarTransport)); if (NS_FAILED(rv)) return rv; if (mCallbacks) { diff --git a/netwerk/base/public/nsIFileTransportService.idl b/netwerk/base/public/nsIFileTransportService.idl index b7ec5d2285e..2f262a30624 100644 --- a/netwerk/base/public/nsIFileTransportService.idl +++ b/netwerk/base/public/nsIFileTransportService.idl @@ -49,8 +49,7 @@ interface nsIFileTransportService : nsISupports { nsITransport createTransport(in nsIFile file, in long ioFlags, - in long perm, - in boolean closeStreamWhenDone); + in long perm); // This version can be used with an existing input stream to serve // as a data pump: @@ -61,8 +60,7 @@ interface nsIFileTransportService : nsISupports in long contentLength, in boolean closeStreamWhenDone); - nsITransport createTransportFromStreamIO(in nsIStreamIO io, - in boolean closeStreamWhenDone); + nsITransport createTransportFromStreamIO(in nsIStreamIO io); void dispatchRequest(in nsIRunnable runnable); void processPendingRequests(); diff --git a/netwerk/base/src/nsFileStreams.cpp b/netwerk/base/src/nsFileStreams.cpp index d374faf9d80..2578d06c4e6 100644 --- a/netwerk/base/src/nsFileStreams.cpp +++ b/netwerk/base/src/nsFileStreams.cpp @@ -307,7 +307,7 @@ nsFileIO::GetInputStream(nsIInputStream * *aInputStream) if (fileIn == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(fileIn); - rv = fileIn->InitWithFileDescriptor(mFD, mFile); + rv = fileIn->InitWithFileDescriptor(mFD, mFile, PR_FALSE); if (NS_SUCCEEDED(rv)) { #ifdef NS_NO_INPUT_BUFFERING *aInputStream = fileIn; @@ -391,15 +391,13 @@ nsFileIO::GetName(nsACString &aName) nsFileStream::nsFileStream() : mFD(nsnull) - , mCloseFD(PR_TRUE) { NS_INIT_REFCNT(); } nsFileStream::~nsFileStream() { - if (mCloseFD) - Close(); + Close(); } NS_IMPL_THREADSAFE_ISUPPORTS1(nsFileStream, nsISeekableStream) @@ -408,8 +406,7 @@ nsresult nsFileStream::Close() { if (mFD) { - if (mCloseFD) - PR_Close(mFD); + PR_Close(mFD); mFD = nsnull; } return NS_OK; @@ -508,8 +505,6 @@ nsFileInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) NS_IMETHODIMP nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm, PRBool deleteOnClose) { - NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED); - nsresult rv = NS_OK; nsCOMPtr localFile = do_QueryInterface(file, &rv); if (NS_FAILED(rv)) return rv; @@ -521,7 +516,18 @@ nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm, PRBool del PRFileDesc* fd; rv = localFile->OpenNSPRFileDesc(ioFlags, perm, &fd); if (NS_FAILED(rv)) return rv; + + return InitWithFileDescriptor(fd, file, deleteOnClose); +} +nsresult +nsFileInputStream::InitWithFileDescriptor(PRFileDesc* fd, nsIFile* file, PRBool deleteOnClose) +{ + NS_ASSERTION(mFD == nsnull, "already inited"); + if (mFD || !fd) + return NS_ERROR_FAILURE; + + mLineBuffer = nsnull; mFD = fd; if (deleteOnClose) { @@ -537,15 +543,6 @@ nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm, PRBool del return NS_OK; } -nsresult -nsFileInputStream::InitWithFileDescriptor(PRFileDesc* fd, nsIFile* file) -{ - NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED); - mFD = fd; - mCloseFD = PR_FALSE; - return NS_OK; -} - NS_IMETHODIMP nsFileInputStream::Close() { @@ -612,7 +609,6 @@ nsFileInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint if (NS_SUCCEEDED(rv)) { rv = writer(this, closure, readBuf, 0, nBytes, _retval); NS_ASSERTION(NS_SUCCEEDED(rv) ? nBytes == *_retval : PR_TRUE, "Didn't write all Data."); - // XXX this assertion is invalid! } nsMemory::Free(readBuf); @@ -651,8 +647,6 @@ nsFileOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) NS_IMETHODIMP nsFileOutputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm) { - NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED); - nsresult rv; nsCOMPtr localFile = do_QueryInterface(file, &rv); if (NS_FAILED(rv)) return rv; @@ -660,22 +654,21 @@ nsFileOutputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm) ioFlags = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE; if (perm <= 0) perm = 0664; - PRFileDesc* fd; rv = localFile->OpenNSPRFileDesc(ioFlags, perm, &fd); if (NS_FAILED(rv)) return rv; - mFD = fd; - return NS_OK; + return InitWithFileDescriptor(fd, file); } nsresult nsFileOutputStream::InitWithFileDescriptor(PRFileDesc* fd, nsIFile* file) { - NS_ENSURE_TRUE(mFD == nsnull, NS_ERROR_ALREADY_INITIALIZED); + NS_ASSERTION(mFD == nsnull, "already inited"); + if (mFD || !fd) + return NS_ERROR_FAILURE; mFD = fd; - mCloseFD = PR_FALSE; return NS_OK; } diff --git a/netwerk/base/src/nsFileStreams.h b/netwerk/base/src/nsFileStreams.h index 78995c8aebe..f7b129a901e 100644 --- a/netwerk/base/src/nsFileStreams.h +++ b/netwerk/base/src/nsFileStreams.h @@ -91,7 +91,6 @@ public: protected: PRFileDesc* mFD; - PRBool mCloseFD; }; //////////////////////////////////////////////////////////////////////////////// @@ -117,7 +116,7 @@ public: static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - nsresult InitWithFileDescriptor(PRFileDesc* fd, nsIFile* file); + nsresult InitWithFileDescriptor(PRFileDesc* fd, nsIFile* file, PRBool deleteOnClose); protected: nsLineBuffer *mLineBuffer; nsCOMPtr mFileToDelete; diff --git a/netwerk/base/src/nsFileTransport.cpp b/netwerk/base/src/nsFileTransport.cpp index 73ad3721802..6660220e11c 100644 --- a/netwerk/base/src/nsFileTransport.cpp +++ b/netwerk/base/src/nsFileTransport.cpp @@ -234,18 +234,14 @@ nsFileTransport::nsFileTransport() } nsresult -nsFileTransport::Init(nsFileTransportService *aService, - nsIFile *file, - PRInt32 ioFlags, - PRInt32 perm, - PRBool closeStreamWhenDone) +nsFileTransport::Init(nsFileTransportService *aService, nsIFile* file, PRInt32 ioFlags, PRInt32 perm) { nsresult rv; nsCOMPtr io; rv = NS_NewFileIO(getter_AddRefs(io), file, ioFlags, perm); if (NS_FAILED(rv)) return rv; - return Init(aService, io, closeStreamWhenDone); + return Init(aService, io); } nsresult @@ -262,13 +258,12 @@ nsFileTransport::Init(nsFileTransportService *aService, rv = NS_NewInputStreamIO(getter_AddRefs(io), name, inStr, contentType, contentCharset, contentLength); if (NS_FAILED(rv)) return rv; - return Init(aService, io, closeStreamWhenDone); + mCloseStreamWhenDone = closeStreamWhenDone; + return Init(aService, io); } nsresult -nsFileTransport::Init(nsFileTransportService *aService, - nsIStreamIO* io, - PRBool closeStreamWhenDone) +nsFileTransport::Init(nsFileTransportService *aService, nsIStreamIO* io) { nsresult rv = NS_OK; if (mLock == nsnull) { @@ -280,8 +275,6 @@ nsFileTransport::Init(nsFileTransportService *aService, rv = mStreamIO->GetName(mStreamName); NS_ASSERTION(NS_SUCCEEDED(rv), "GetName failed"); - mCloseStreamWhenDone = closeStreamWhenDone; - NS_ADDREF(mService = aService); PR_AtomicIncrement(&mService->mTotalTransports); diff --git a/netwerk/base/src/nsFileTransport.h b/netwerk/base/src/nsFileTransport.h index b67be33daad..2a1720779af 100644 --- a/netwerk/base/src/nsFileTransport.h +++ b/netwerk/base/src/nsFileTransport.h @@ -88,17 +88,14 @@ public: nsresult Init(nsFileTransportService *aService, nsIFile* file, PRInt32 ioFlags, - PRInt32 perm, - PRBool closeStreamWhenDone); + PRInt32 perm); nsresult Init(nsFileTransportService *aService, const nsACString &name, nsIInputStream *fromStream, const nsACString &contentType, const nsACString &contentCharset, PRInt32 contentLength, PRBool closeStreamWhenDone); - nsresult Init(nsFileTransportService *aService, - nsIStreamIO* io, - PRBool closeStreamWhenDone); + nsresult Init(nsFileTransportService *aService, nsIStreamIO* io); void Process(nsIProgressEventSink *); void DoClose(void); diff --git a/netwerk/base/src/nsFileTransportService.cpp b/netwerk/base/src/nsFileTransportService.cpp index be5c41e487a..3b7efcb8cb4 100644 --- a/netwerk/base/src/nsFileTransportService.cpp +++ b/netwerk/base/src/nsFileTransportService.cpp @@ -127,7 +127,6 @@ NS_IMETHODIMP nsFileTransportService::CreateTransport(nsIFile* file, PRInt32 ioFlags, PRInt32 perm, - PRBool closeStreamWhenDone, nsITransport** result) { nsresult rv; @@ -135,7 +134,7 @@ nsFileTransportService::CreateTransport(nsIFile* file, if (trans == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(trans); - rv = trans->Init(this, file, ioFlags, perm, closeStreamWhenDone); + rv = trans->Init(this, file, ioFlags, perm); if (NS_FAILED(rv)) { NS_RELEASE(trans); return rv; @@ -171,7 +170,6 @@ nsFileTransportService::CreateTransportFromStream(const nsACString &name, NS_IMETHODIMP nsFileTransportService::CreateTransportFromStreamIO(nsIStreamIO *io, - PRBool closeStreamWhenDone, nsITransport **result) { nsresult rv; @@ -179,7 +177,7 @@ nsFileTransportService::CreateTransportFromStreamIO(nsIStreamIO *io, if (trans == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(trans); - rv = trans->Init(this, io, closeStreamWhenDone); + rv = trans->Init(this, io); if (NS_FAILED(rv)) { NS_RELEASE(trans); return rv; diff --git a/netwerk/base/src/nsInputStreamChannel.cpp b/netwerk/base/src/nsInputStreamChannel.cpp index 668a06c30cc..5348bc08943 100644 --- a/netwerk/base/src/nsInputStreamChannel.cpp +++ b/netwerk/base/src/nsInputStreamChannel.cpp @@ -311,10 +311,9 @@ nsStreamIOChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) do_GetService(kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) goto done; - rv = fts->CreateTransportFromStreamIO(mStreamIO, PR_TRUE, - getter_AddRefs(mFileTransport)); - if (NS_FAILED(rv)) goto done; - } + rv = fts->CreateTransportFromStreamIO(mStreamIO, getter_AddRefs(mFileTransport)); + if (NS_FAILED(rv)) goto done; + } // Hook up the notification callbacks InterfaceRequestor... { diff --git a/netwerk/cache/src/nsDiskCacheDevice.cpp b/netwerk/cache/src/nsDiskCacheDevice.cpp index 29324dacb1e..d2450b109c8 100644 --- a/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -580,7 +580,7 @@ nsDiskCacheDevice::GetTransportForEntry(nsCacheEntry * entry, break; } - rv = gFileTransportService->CreateTransport(file, ioFlags, PR_IRUSR | PR_IWUSR, PR_FALSE, result); + rv = gFileTransportService->CreateTransport(file, ioFlags, PR_IRUSR | PR_IWUSR, result); return rv; } diff --git a/netwerk/mime/src/nsXMLMIMEDataSource.cpp b/netwerk/mime/src/nsXMLMIMEDataSource.cpp index 3c91ff01b75..277d51eb9ce 100644 --- a/netwerk/mime/src/nsXMLMIMEDataSource.cpp +++ b/netwerk/mime/src/nsXMLMIMEDataSource.cpp @@ -308,11 +308,7 @@ nsXMLMIMEDataSource::Serialize() { do_GetService(kFileTransportServiceCID, &rv) ; if(NS_FAILED(rv)) return rv ; - rv = fts->CreateTransport(mFile, - PR_WRONLY|PR_CREATE_FILE, - PR_IRWXU, - PR_TRUE, - getter_AddRefs(transport)) ; + rv = fts->CreateTransport(mFile, PR_WRONLY|PR_CREATE_FILE, PR_IRWXU, getter_AddRefs(transport)) ; if(NS_FAILED(rv)) return rv ; @@ -730,11 +726,7 @@ nsXMLMIMEDataSource::InitFromFile( nsIFile* aFile ) do_GetService(kFileTransportServiceCID, &rv) ; if(NS_FAILED(rv)) return rv ; // Made second parameter 0 since I really don't know what it is used for - rv = fts->CreateTransport(aFile, - PR_RDONLY, - PR_IRWXU, - PR_TRUE, - getter_AddRefs(transport)) ; + rv = fts->CreateTransport(aFile, PR_RDONLY, PR_IRWXU, getter_AddRefs(transport)) ; if(NS_FAILED(rv)) return rv ; diff --git a/netwerk/protocol/file/src/nsFileChannel.cpp b/netwerk/protocol/file/src/nsFileChannel.cpp index 69e5025fdfb..f5f787ae4f4 100644 --- a/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/netwerk/protocol/file/src/nsFileChannel.cpp @@ -231,7 +231,7 @@ nsFileChannel::EnsureTransport() do_GetService(kFileTransportServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(mFile, mIOFlags, mPerm, PR_TRUE, + rv = fts->CreateTransport(mFile, mIOFlags, mPerm, getter_AddRefs(mFileTransport)); if (NS_FAILED(rv)) return rv; diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index c0b47f85841..fab81ec6d91 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -59,7 +59,6 @@ nsHttpChannel::nsHttpChannel() , mConnectionInfo(nsnull) , mLoadFlags(LOAD_NORMAL) , mStatus(NS_OK) - , mLogicalOffset(0) , mCapabilities(0) , mReferrerType(REFERRER_NONE) , mCachedResponseHead(nsnull) @@ -71,7 +70,6 @@ nsHttpChannel::nsHttpChannel() , mApplyConversion(PR_TRUE) , mFromCacheOnly(PR_FALSE) , mCachedContentIsValid(PR_FALSE) - , mCachedContentIsPartial(PR_FALSE) , mResponseHeadersModified(PR_FALSE) , mCanceled(PR_FALSE) , mUploadStreamHasHeaders(PR_FALSE) @@ -391,7 +389,7 @@ nsHttpChannel::SetupTransaction() if (mConnectionInfo->UsingSSL() || !mConnectionInfo->UsingHttpProxy()) { rv = mURI->GetPath(path); if (NS_FAILED(rv)) return rv; - // path may contain UTF-8 characters, so ensure that they're escaped. + // path may contain UTF-8 characters, so ensure that their escaped. if (NS_EscapeURL(path.get(), path.Length(), esc_OnlyNonASCII, buf)) requestURI = buf.get(); else @@ -491,15 +489,10 @@ nsHttpChannel::ProcessResponse() switch (httpStatus) { case 200: case 203: + case 206: // these can normally be cached rv = ProcessNormal(); break; - case 206: - if (mCachedContentIsPartial) // an internal byte range request... - rv = ProcessPartialContent(); - else - rv = ProcessNormal(); - break; case 300: case 301: case 302: @@ -603,160 +596,6 @@ nsHttpChannel::ProcessNormal() return rv; } -//----------------------------------------------------------------------------- -// nsHttpChannel -//----------------------------------------------------------------------------- - -nsresult -nsHttpChannel::SetupByteRangeRequest(PRUint32 partialLen) -{ - // cached content has been found to be partial, add necessary request - // headers to complete cache entry. - - // use strongest validator available... - const char *val = mCachedResponseHead->PeekHeader(nsHttp::ETag); - if (!val) - val = mCachedResponseHead->PeekHeader(nsHttp::Last_Modified); - if (!val) { - // if we hit this code it means mCachedResponseHead->IsResumable() is - // either broken or not being called. - NS_NOTREACHED("no cache validator"); - return NS_ERROR_FAILURE; - } - - char buf[32]; - PR_snprintf(buf, sizeof(buf), "bytes=%u-", partialLen); - - mRequestHead.SetHeader(nsHttp::Range, nsDependentCString(buf)); - mRequestHead.SetHeader(nsHttp::If_Range, nsDependentCString(val)); - - return NS_OK; -} - -nsresult -nsHttpChannel::ProcessPartialContent() -{ - nsresult rv; - - // ok, we've just received a 206 - // - // we need to stream whatever data is in the cache out first, and then - // pick up whatever data is on the wire, writing it into the cache. - - LOG(("nsHttpChannel::ProcessPartialContent [this=%x]\n", this)); - - NS_ENSURE_TRUE(mCachedResponseHead, NS_ERROR_NOT_INITIALIZED); - NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_NOT_INITIALIZED); - - // suspend the current transaction (may still get an OnDataAvailable) - rv = mTransaction->Suspend(); - if (NS_FAILED(rv)) return rv; - - // merge any new headers with the cached response headers - rv = mCachedResponseHead->UpdateHeaders(mResponseHead->Headers()); - if (NS_FAILED(rv)) return rv; - - // update the cached response head - nsCAutoString head; - mCachedResponseHead->Flatten(head, PR_TRUE); - rv = mCacheEntry->SetMetaDataElement("response-head", head.get()); - if (NS_FAILED(rv)) return rv; - - // make the cached response be the current response - delete mResponseHead; - mResponseHead = mCachedResponseHead; - mCachedResponseHead = 0; - - rv = UpdateExpirationTime(); - if (NS_FAILED(rv)) return rv; - - // the cached content is valid, although incomplete. - mCachedContentIsValid = PR_TRUE; - return ReadFromCache(); -} - -nsresult -nsHttpChannel::BufferPartialContent(nsIInputStream *input, PRUint32 count) -{ - nsresult rv; - - LOG(("nsHttpChannel::BufferPartialContent [this=%x count=%u]\n", this, count)); - - if (!mBufferOut) { - LOG(("creating pipe...\n")); - // - // create a pipe for buffering network data (the size of this - // pipe must be equal to or greater than the size of the pipe - // used to proxy data from the socket transport thread). - // - rv = NS_NewPipe(getter_AddRefs(mBufferIn), - getter_AddRefs(mBufferOut), - NS_HTTP_SEGMENT_SIZE, - NS_HTTP_BUFFER_SIZE, - PR_TRUE, - PR_TRUE); - if (NS_FAILED(rv)) return rv; - } - - PRUint32 bytesWritten = 0; - rv = mBufferOut->WriteFrom(input, count, &bytesWritten); - if (NS_FAILED(rv) || (bytesWritten != count)) { - LOG(("writing to pipe failed [rv=%s bytes-written=%u]\n", rv, bytesWritten)); - return NS_ERROR_UNEXPECTED; - } - - return NS_OK; -} - -nsresult -nsHttpChannel::OnDoneReadingPartialCacheEntry(PRBool *streamDone) -{ - nsresult rv; - - LOG(("nsHttpChannel::OnDoneReadingPartialCacheEntry [this=%x]", this)); - - // by default, assume we would have streamed all data or failed... - *streamDone = PR_TRUE; - - // setup cache listener to append to cache entry - PRUint32 size; - rv = mCacheEntry->GetDataSize(&size); - if (NS_FAILED(rv)) return rv; - - rv = InstallCacheListener(size); - if (NS_FAILED(rv)) return rv; - - // process any buffered data - if (mBufferIn) { - PRUint32 avail; - rv = mBufferIn->Available(&avail); - if (NS_FAILED(rv)) return rv; - - rv = mListener->OnDataAvailable(this, mListenerContext, mBufferIn, size, avail); - if (NS_FAILED(rv)) return rv; - - // done with the pipe - mBufferIn = 0; - mBufferOut = 0; - } - - // need to track the logical offset of the data being sent to our listener - mLogicalOffset = size; - - // we're now completing the cached content, so we can clear this flag. - // this puts us in the state of a regular download. - mCachedContentIsPartial = PR_FALSE; - - // resume the transaction if it exists, otherwise the pipe contained the - // remaining part of the document and we've now streamed all of the data. - if (mTransaction) { - rv = mTransaction->Resume(); - if (NS_SUCCEEDED(rv)) - *streamDone = PR_FALSE; - } - return rv; -} - //----------------------------------------------------------------------------- // nsHttpChannel //----------------------------------------------------------------------------- @@ -825,10 +664,7 @@ nsHttpChannel::OpenCacheEntry(PRBool *delayed) return NS_OK; } else if (mRequestHead.PeekHeader(nsHttp::Range)) { - // we don't support caching for byte range requests initiated - // by our clients. - // XXX perhaps we could munge their byte range into the cache - // key to make caching sort'a work. + // we don't support caching for byte range requests return NS_OK; } @@ -1014,24 +850,18 @@ nsHttpChannel::CheckCache() } // If the cached content-length is set and it does not match the data size - // of the cached content, then the cached response is partial... - // either we need to issue a byte range request or we need to refetch the - // entire document. - PRUint32 contentLength = (PRUint32) mCachedResponseHead->ContentLength(); - if (contentLength != PRUint32(-1)) { + // of the cached content, then refetch. + PRInt32 contentLength = mCachedResponseHead->ContentLength(); + if (contentLength != -1) { PRUint32 size; rv = mCacheEntry->GetDataSize(&size); if (NS_FAILED(rv)) return rv; - if (size != contentLength) { + if (size != (PRUint32) contentLength) { LOG(("Cached data size does not match the Content-Length header " "[content-length=%u size=%u]\n", contentLength, size)); - if ((size < contentLength) && mCachedResponseHead->IsResumable()) { - // looks like a partial entry. - rv = SetupByteRangeRequest(size); - if (NS_FAILED(rv)) return rv; - mCachedContentIsPartial = PR_TRUE; - } + // looks like a partial entry. + // XXX must re-fetch until we learn how to do byte range requests. return NS_OK; } } @@ -1172,7 +1002,7 @@ nsHttpChannel::ReadFromCache() if (!mSecurityInfo) mCacheEntry->GetSecurityInfo(getter_AddRefs(mSecurityInfo)); - if ((mCacheAccess & nsICache::ACCESS_WRITE) && !mCachedContentIsPartial) { + if (mCacheAccess & nsICache::ACCESS_WRITE) { // We have write access to the cache, but we don't need to go to the // server to validate at this time, so just mark the cache entry as // valid in order to allow others access to this cache entry. @@ -1320,22 +1150,17 @@ nsHttpChannel::FinalizeCacheEntry() // Open an output stream to the cache entry and insert a listener tee into // the chain of response listeners. nsresult -nsHttpChannel::InstallCacheListener(PRUint32 offset) +nsHttpChannel::InstallCacheListener() { nsresult rv; LOG(("Preparing to write data into the cache [uri=%s]\n", mSpec.get())); - NS_ASSERTION(mCacheEntry, "no cache entry"); - NS_ASSERTION(mListener, "no listener"); - - if (!mCacheTransport) { - rv = mCacheEntry->GetTransport(getter_AddRefs(mCacheTransport)); - if (NS_FAILED(rv)) return rv; - } + rv = mCacheEntry->GetTransport(getter_AddRefs(mCacheTransport)); + if (NS_FAILED(rv)) return rv; nsCOMPtr out; - rv = mCacheTransport->OpenOutputStream(offset, PRUint32(-1), 0, getter_AddRefs(out)); + rv = mCacheTransport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(out)); if (NS_FAILED(rv)) return rv; // XXX disk cache does not support overlapped i/o yet @@ -2711,17 +2536,14 @@ nsHttpChannel::GetContentEncodings(nsISimpleEnumerator** aEncodings) NS_IMETHODIMP nsHttpChannel::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { - if (!(mCanceled || NS_FAILED(mStatus))) { - // capture the request's status, so our consumers will know ASAP of any - // connection failures, etc - bug 93581 - request->GetStatus(&mStatus); - } + // capture the request's status, so our consumers will know ASAP of any + // connection failures, etc - bug 93581 + request->GetStatus(&mStatus); LOG(("nsHttpChannel::OnStartRequest [this=%x request=%x status=%x]\n", this, request, mStatus)); - // don't enter this block if we're reading from the cache... - if (NS_SUCCEEDED(mStatus) && !mCacheReadRequest && mTransaction) { + if (mTransaction) { // grab the security info from the connection object; the transaction // is guaranteed to own a reference to the connection. mSecurityInfo = mTransaction->SecurityInfo(); @@ -2756,23 +2578,6 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st mPrevTransaction = nsnull; } - if (mCachedContentIsPartial && NS_SUCCEEDED(status)) { - if (request == mTransaction) { - // byte-range transaction finished before we got around to streaming it. - NS_ASSERTION(mCacheReadRequest, "should be reading from cache right now"); - NS_RELEASE(mTransaction); - mTransaction = nsnull; - return NS_OK; - } - if (request == mCacheReadRequest) { - PRBool streamDone; - status = OnDoneReadingPartialCacheEntry(&streamDone); - if (NS_SUCCEEDED(status) && !streamDone) - return status; - // otherwise, fall through and fire OnStopRequest... - } - } - // if the request is for something we no longer reference, then simply // drop this event. if ((request != mTransaction) && (request != mCacheReadRequest)) @@ -2781,11 +2586,8 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st mIsPending = PR_FALSE; mStatus = status; - PRBool isPartial = PR_FALSE; + // at this point, we're done with the transaction if (mTransaction) { - // find out if the transaction ran to completion... - isPartial = !mTransaction->ResponseIsComplete(); - // at this point, we're done with the transaction NS_RELEASE(mTransaction); mTransaction = nsnull; } @@ -2807,21 +2609,12 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st } if (mCacheEntry) { - nsresult closeStatus = status; - if (mCanceled) { - // we don't want to discard the cache entry if canceled and - // reading from the cache. - if (request == mCacheReadRequest) - closeStatus = NS_OK; - // we also don't want to discard the cache entry if the - // server supports byte range requests, because we could always - // complete the download at a later time. - else if (isPartial && mResponseHead && mResponseHead->IsResumable()) { - LOG(("keeping partial response that is resumable!\n")); - closeStatus = NS_OK; - } - } - CloseCacheEntry(closeStatus); + // we don't want to discard the cache entry if canceled and + // reading from the cache. + if (mCanceled && (request == mCacheReadRequest)) + CloseCacheEntry(NS_OK); + else + CloseCacheEntry(status); } if (mLoadGroup) @@ -2842,11 +2635,6 @@ nsHttpChannel::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, LOG(("nsHttpChannel::OnDataAvailable [this=%x request=%x offset=%u count=%u]\n", this, request, offset, count)); - if (mCachedContentIsPartial && (request == mTransaction)) { - // XXX we can eliminate this buffer once bug 93055 is resolved. - return BufferPartialContent(input, count); - } - // if the request is for something we no longer reference, then simply // drop this event. if ((request != mTransaction) && (request != mCacheReadRequest)) { @@ -2854,21 +2642,8 @@ nsHttpChannel::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, return NS_BASE_STREAM_CLOSED; } - if (mListener) { - // - // we have to manually keep the logical offset of the stream up-to-date. - // we cannot depend soley on the offset provided, since we may have - // already streamed some data from another source (see, for example, - // OnDoneReadingPartialCacheEntry). - // - nsresult rv = mListener->OnDataAvailable(this, - mListenerContext, - input, - mLogicalOffset, - count); - mLogicalOffset += count; - return rv; - } + if (mListener) + return mListener->OnDataAvailable(this, mListenerContext, input, offset, count); return NS_BASE_STREAM_CLOSED; } diff --git a/netwerk/protocol/http/src/nsHttpChannel.h b/netwerk/protocol/http/src/nsHttpChannel.h index e57af3aad69..2237fee6db0 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.h +++ b/netwerk/protocol/http/src/nsHttpChannel.h @@ -40,12 +40,10 @@ #include "nsICacheListener.h" #include "nsITransport.h" #include "nsIUploadChannel.h" -#include "nsISimpleEnumerator.h" -#include "nsIInputStream.h" -#include "nsIOutputStream.h" #include "nsCOMPtr.h" #include "nsXPIDLString.h" #include "nsHttpConnection.h" +#include "nsISimpleEnumerator.h" class nsHttpTransaction; class nsHttpResponseHead; @@ -108,13 +106,7 @@ private: nsresult InitCacheEntry(); nsresult StoreAuthorizationMetaData(); nsresult FinalizeCacheEntry(); - nsresult InstallCacheListener(PRUint32 offset = 0); - - // byte range request specific methods - nsresult SetupByteRangeRequest(PRUint32 partialLen); - nsresult ProcessPartialContent(); - nsresult BufferPartialContent(nsIInputStream *, PRUint32 count); - nsresult OnDoneReadingPartialCacheEntry(PRBool *streamDone); + nsresult InstallCacheListener(); // auth specific methods nsresult GetCredentials(const char *challenges, PRBool proxyAuth, nsAFlatCString &creds); @@ -157,7 +149,6 @@ private: PRUint32 mLoadFlags; PRUint32 mStatus; - PRUint32 mLogicalOffset; PRUint8 mCapabilities; PRUint8 mReferrerType; @@ -170,10 +161,6 @@ private: PRUint32 mPostID; PRUint32 mRequestTime; - // byte-range specific data - nsCOMPtr mBufferIn; - nsCOMPtr mBufferOut; - // auth specific data nsXPIDLString mUser; nsXPIDLString mPass; @@ -187,7 +174,6 @@ private: PRPackedBool mApplyConversion; PRPackedBool mFromCacheOnly; PRPackedBool mCachedContentIsValid; - PRPackedBool mCachedContentIsPartial; PRPackedBool mResponseHeadersModified; PRPackedBool mCanceled; PRPackedBool mUploadStreamHasHeaders; diff --git a/netwerk/protocol/http/src/nsHttpResponseHead.cpp b/netwerk/protocol/http/src/nsHttpResponseHead.cpp index 66965201596..7084c3159fb 100644 --- a/netwerk/protocol/http/src/nsHttpResponseHead.cpp +++ b/netwerk/protocol/http/src/nsHttpResponseHead.cpp @@ -363,17 +363,6 @@ nsHttpResponseHead::MustValidateIfExpired() return val && PL_strcasestr(val, "must-revalidate"); } -PRBool -nsHttpResponseHead::IsResumable() -{ - // even though some HTTP/1.0 servers may support byte range requests, we're not - // going to bother with them, since those servers wouldn't understand If-Range. - return mVersion >= NS_HTTP_VERSION_1_1 && - PeekHeader(nsHttp::Content_Length) && - (PeekHeader(nsHttp::ETag) || PeekHeader(nsHttp::Last_Modified)) && - PL_strcasestr(PeekHeader(nsHttp::Accept_Ranges), "bytes"); -} - PRBool nsHttpResponseHead::ExpiresInPast() { diff --git a/netwerk/protocol/http/src/nsHttpResponseHead.h b/netwerk/protocol/http/src/nsHttpResponseHead.h index 04366e6a8d8..8e26b4edc4a 100644 --- a/netwerk/protocol/http/src/nsHttpResponseHead.h +++ b/netwerk/protocol/http/src/nsHttpResponseHead.h @@ -87,9 +87,6 @@ public: PRBool MustValidate(); PRBool MustValidateIfExpired(); - // returns true if the server appears to support byte range requests. - PRBool IsResumable(); - // returns true if the Expires header has a value in the past relative to the // value of the Date header. PRBool ExpiresInPast(); diff --git a/netwerk/protocol/http/src/nsHttpTransaction.cpp b/netwerk/protocol/http/src/nsHttpTransaction.cpp index 6d177d27691..4d5cef5fb17 100644 --- a/netwerk/protocol/http/src/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/src/nsHttpTransaction.cpp @@ -95,7 +95,6 @@ nsHttpTransaction::nsHttpTransaction(nsIStreamListener *listener, , mCapabilities(caps) , mHaveStatusLine(PR_FALSE) , mHaveAllHeaders(PR_FALSE) - , mResponseIsComplete(PR_FALSE) , mFiredOnStart(PR_FALSE) , mNoContent(PR_FALSE) , mPrematureEOF(PR_FALSE) @@ -618,7 +617,6 @@ nsHttpTransaction::HandleContent(char *buf, // OnTransactionComplete is fired only once! PRInt32 priorVal = PR_AtomicSet(&mTransactionDone, 1); if (priorVal == 0) { - mResponseIsComplete = PR_TRUE; // let the connection know that we are done with it; this should // result in OnStopTransaction being fired. return mConnection->OnTransactionComplete(this, NS_OK); diff --git a/netwerk/protocol/http/src/nsHttpTransaction.h b/netwerk/protocol/http/src/nsHttpTransaction.h index 0fdc690eb50..cb9f148267f 100644 --- a/netwerk/protocol/http/src/nsHttpTransaction.h +++ b/netwerk/protocol/http/src/nsHttpTransaction.h @@ -78,9 +78,6 @@ public: // will drop any reference to the response headers after this call. nsHttpResponseHead *TakeResponseHead(); - // Called to find out if the transaction generated a complete response. - PRBool ResponseIsComplete() { return mResponseIsComplete; } - // nsAHttpTransaction methods: void SetConnection(nsAHttpConnection *conn) { NS_IF_ADDREF(mConnection = conn); } void SetSecurityInfo(nsISupports *info) { mSecurityInfo = info; } @@ -136,7 +133,6 @@ private: PRPackedBool mHaveStatusLine; PRPackedBool mHaveAllHeaders; - PRPackedBool mResponseIsComplete; PRPackedBool mFiredOnStart; PRPackedBool mNoContent; // expecting an empty entity body? PRPackedBool mPrematureEOF; diff --git a/netwerk/protocol/jar/src/nsJARChannel.cpp b/netwerk/protocol/jar/src/nsJARChannel.cpp index 3e843fc80c9..1f208ffbea8 100644 --- a/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -339,7 +339,7 @@ nsJARChannel::AsyncReadJARElement() if (NS_FAILED(rv)) return rv; nsCOMPtr jarTransport; - rv = fts->CreateTransportFromStreamIO(this, PR_TRUE, getter_AddRefs(jarTransport)); + rv = fts->CreateTransportFromStreamIO(this, getter_AddRefs(jarTransport)); if (NS_FAILED(rv)) return rv; if (mCallbacks) { diff --git a/netwerk/test/TestFileInput.cpp b/netwerk/test/TestFileInput.cpp index 3cfbcd5db3c..e91d8d86b9c 100644 --- a/netwerk/test/TestFileInput.cpp +++ b/netwerk/test/TestFileInput.cpp @@ -366,7 +366,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) NS_ASSERTION(listener, "QI failed"); nsITransport* trans; - rv = fts->CreateTransport(file, PR_RDONLY, 0, PR_TRUE, &trans); + rv = fts->CreateTransport(file, PR_RDONLY, 0, &trans); NS_ASSERTION(NS_SUCCEEDED(rv), "create failed"); nsCOMPtr request; rv = trans->AsyncRead(nsnull, listener, 0, -1, 0, getter_AddRefs(request)); diff --git a/netwerk/test/TestFileTransport.cpp b/netwerk/test/TestFileTransport.cpp index bc8784c4272..5f41e363623 100644 --- a/netwerk/test/TestFileTransport.cpp +++ b/netwerk/test/TestFileTransport.cpp @@ -204,7 +204,7 @@ TestAsyncRead(const char* fileName, PRUint32 offset, PRInt32 length) nsCOMPtr file; rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; - rv = fts->CreateTransport(file, PR_RDONLY, 0, PR_TRUE, &fileTrans); + rv = fts->CreateTransport(file, PR_RDONLY, 0, &fileTrans); if (NS_FAILED(rv)) return rv; MyListener* listener = new MyListener(); @@ -260,7 +260,7 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) if (NS_FAILED(rv)) return rv; rv = fts->CreateTransport(file, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, - 0664, PR_TRUE, &fileTrans); + 0664, &fileTrans); if (NS_FAILED(rv)) return rv; MyListener* listener = new MyListener(); diff --git a/netwerk/test/TestWriteStream.cpp b/netwerk/test/TestWriteStream.cpp index cb346571138..dc740cb40e9 100644 --- a/netwerk/test/TestWriteStream.cpp +++ b/netwerk/test/TestWriteStream.cpp @@ -133,7 +133,7 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length) if (NS_FAILED(rv)) return rv ; nsCOMPtr transport; - rv = fts->CreateTransport(fs, PR_RDWR | PR_CREATE_FILE, 0664, PR_TRUE, + rv = fts->CreateTransport(fs, PR_RDWR | PR_CREATE_FILE, 0664, getter_AddRefs(transport)) ; if (NS_FAILED(rv)) return rv ; diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index c10e48f3a41..d2d5c4a3c05 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -1030,14 +1030,10 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel) if (NS_FAILED(rv)) return rv; nsCOMPtr fileTransport; - rv = fts->CreateTransport(mTempFile, - PR_WRONLY | PR_CREATE_FILE, - 0600, - PR_TRUE, - getter_AddRefs(fileTransport)); + rv = fts->CreateTransport(mTempFile, PR_WRONLY | PR_CREATE_FILE, 0600, getter_AddRefs(fileTransport)); if (NS_FAILED(rv)) return rv; - rv = fileTransport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(mOutStream)); + rv = fileTransport->OpenOutputStream(0, -1, 0, getter_AddRefs(mOutStream)); #ifdef XP_MAC nsXPIDLCString contentType; diff --git a/xpfe/components/xfer/src/nsStreamXferOp.cpp b/xpfe/components/xfer/src/nsStreamXferOp.cpp index 7b38ca759fb..dedfd41e94c 100644 --- a/xpfe/components/xfer/src/nsStreamXferOp.cpp +++ b/xpfe/components/xfer/src/nsStreamXferOp.cpp @@ -168,7 +168,6 @@ nsStreamXferOp::Start( void ) { rv = fts->CreateTransport( mOutputFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664, - PR_TRUE, getter_AddRefs( mOutputTransport ) ); if ( NS_SUCCEEDED( rv ) ) { diff --git a/xpinstall/src/nsXPInstallManager.cpp b/xpinstall/src/nsXPInstallManager.cpp index 693048570eb..94446a95383 100644 --- a/xpinstall/src/nsXPInstallManager.cpp +++ b/xpinstall/src/nsXPInstallManager.cpp @@ -777,7 +777,6 @@ nsXPInstallManager::OnStartRequest(nsIRequest* request, nsISupports *ctxt) rv = fts->CreateTransport(mItem->mFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664, - PR_TRUE, getter_AddRefs( outTransport)); if (NS_SUCCEEDED(rv))