зеркало из https://github.com/mozilla/pjs.git
Bug 227057 remove nsIResumableEntityID in favor of using strings for the entity
id. r=darin sr=bzbarsky
This commit is contained in:
Родитель
6395cedb06
Коммит
5db61a33cb
|
@ -84,7 +84,6 @@ XPIDLSRCS = \
|
|||
nsISocketTransportService.idl \
|
||||
nsIServerSocket.idl \
|
||||
nsIResumableChannel.idl \
|
||||
nsIResumableEntityID.idl \
|
||||
nsIRequestObserverProxy.idl \
|
||||
nsIStreamListenerProxy.idl \
|
||||
nsIStreamListenerTee.idl \
|
||||
|
|
|
@ -37,9 +37,8 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIStreamListener;
|
||||
interface nsIResumableEntityID;
|
||||
|
||||
[scriptable, uuid(87cccd68-1dd2-11b2-8b66-cbf10a1b6438)]
|
||||
[scriptable, uuid(4ad136fa-83af-4a22-a76e-503642c0f4a8)]
|
||||
interface nsIResumableChannel : nsISupports {
|
||||
/**
|
||||
* Prepare this channel for resuming. The request will not start until
|
||||
|
@ -48,7 +47,7 @@ interface nsIResumableChannel : nsISupports {
|
|||
*
|
||||
* @param startPos the starting offset, in bytes, to use to download
|
||||
* @param entityID information about the file, to match before obtaining
|
||||
* the file. Pass null to use anything.
|
||||
* the file. Pass an empty string to use anything.
|
||||
*
|
||||
* During OnStartRequest, this channel will have a status of
|
||||
* NS_ERROR_NOT_RESUMABLE if the file cannot be resumed, eg because the
|
||||
|
@ -61,11 +60,11 @@ interface nsIResumableChannel : nsISupports {
|
|||
* OnStopRequest will immediately follow with the same status code.
|
||||
*/
|
||||
void resumeAt(in unsigned long long startPos,
|
||||
in nsIResumableEntityID entityID);
|
||||
in ACString entityID);
|
||||
|
||||
/**
|
||||
* The nsIResumableEntityID for this URI. Available after OnStartRequest.
|
||||
* If this attribute is null, then this load is not resumable.
|
||||
* The entity id for this URI. Available after OnStartRequest.
|
||||
* @throw NS_ERROR_NOT_RESUMABLE if this load is not resumable.
|
||||
*/
|
||||
readonly attribute nsIResumableEntityID entityID;
|
||||
readonly attribute ACString entityID;
|
||||
};
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
#include "nsIStreamTransportService.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIDownloader.h"
|
||||
#include "nsIResumableEntityID.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsIUnicharStreamLoader.h"
|
||||
#include "nsIPipe.h"
|
||||
|
@ -617,24 +616,6 @@ NS_GetURLSpecFromFile(nsIFile *aFile,
|
|||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewResumableEntityID(nsIResumableEntityID **aRes,
|
||||
PRUint64 size,
|
||||
const nsACString &lastModified,
|
||||
const nsACString &entityTag)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIResumableEntityID> ent =
|
||||
do_CreateInstance(NS_RESUMABLEENTITYID_CONTRACTID,&rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
ent->SetSize(size);
|
||||
ent->SetLastModified(lastModified);
|
||||
ent->SetEntityTag(entityTag);
|
||||
NS_ADDREF(*aRes = ent);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_ExamineForProxy(const char *scheme,
|
||||
const char *host,
|
||||
|
|
|
@ -69,7 +69,6 @@ CPPSRCS = \
|
|||
nsMIMEInputStream.cpp \
|
||||
nsProtocolProxyService.cpp \
|
||||
nsRequestObserverProxy.cpp \
|
||||
nsResumableEntityID.cpp \
|
||||
nsSimpleStreamListener.cpp \
|
||||
nsSimpleURI.cpp \
|
||||
nsStandardURL.cpp \
|
||||
|
|
|
@ -335,19 +335,6 @@
|
|||
{0xa9, 0x04, 0xac, 0x1d, 0x6d, 0xa7, 0x7a, 0x02} \
|
||||
}
|
||||
|
||||
// component implementing nsIResumableEntityID
|
||||
#define NS_RESUMABLEENTITYID_CLASSNAME \
|
||||
"nsResumableEntityID"
|
||||
#define NS_RESUMABLEENTITYID_CONTRACTID \
|
||||
"@mozilla.org/network/resumable-entity-id;1"
|
||||
#define NS_RESUMABLEENTITYID_CID \
|
||||
{ /* e744a9a6-1dd1-11b2-b95c-e5d67a34e6b3 */ \
|
||||
0xe744a9a6, \
|
||||
0x1d11, \
|
||||
0x11b2, \
|
||||
{0xb9, 0x5c, 0xe5, 0xd6, 0x7a, 0x34, 0xe6, 0xb3} \
|
||||
}
|
||||
|
||||
// service implementing nsIStreamTransportService
|
||||
#define NS_STREAMTRANSPORTSERVICE_CLASSNAME \
|
||||
"nsStreamTransportService"
|
||||
|
|
|
@ -220,11 +220,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsStandardURL)
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsResumableEntityID.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsResumableEntityID)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsIDNService.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsIDNService, Init)
|
||||
|
||||
|
@ -703,12 +698,6 @@ static const nsModuleComponentInfo gNetModuleInfo[] = {
|
|||
nsURICheckerConstructor
|
||||
},
|
||||
|
||||
{ NS_RESUMABLEENTITYID_CLASSNAME,
|
||||
NS_RESUMABLEENTITYID_CID,
|
||||
NS_RESUMABLEENTITYID_CONTRACTID,
|
||||
nsResumableEntityIDConstructor
|
||||
},
|
||||
|
||||
// The register functions for the built-in
|
||||
// parsers just need to be called once.
|
||||
{ NS_STDURLPARSER_CLASSNAME,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set ts=4 sts=4 sw=4 et cin: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -277,12 +278,12 @@ nsFTPChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
|
|||
nsresult rv = AsyncOpenAt(listener, ctxt, mStartPos, mEntityID);
|
||||
// mEntityID no longer needed, clear it to avoid returning a wrong entity
|
||||
// id when someone asks us
|
||||
mEntityID = nsnull;
|
||||
mEntityID.Truncate();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFTPChannel::ResumeAt(PRUint64 aStartPos, nsIResumableEntityID* aEntityID)
|
||||
nsFTPChannel::ResumeAt(PRUint64 aStartPos, const nsACString& aEntityID)
|
||||
{
|
||||
mEntityID = aEntityID;
|
||||
mStartPos = aStartPos;
|
||||
|
@ -290,16 +291,18 @@ nsFTPChannel::ResumeAt(PRUint64 aStartPos, nsIResumableEntityID* aEntityID)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFTPChannel::GetEntityID(nsIResumableEntityID **entityID)
|
||||
nsFTPChannel::GetEntityID(nsACString& entityID)
|
||||
{
|
||||
*entityID = mEntityID;
|
||||
NS_IF_ADDREF(*entityID);
|
||||
if (mEntityID.IsEmpty())
|
||||
return NS_ERROR_NOT_RESUMABLE;
|
||||
|
||||
entityID = mEntityID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFTPChannel::AsyncOpenAt(nsIStreamListener *listener, nsISupports *ctxt,
|
||||
PRUint64 startPos, nsIResumableEntityID* entityID)
|
||||
PRUint64 startPos, const nsACString& entityID)
|
||||
{
|
||||
PRInt32 port;
|
||||
nsresult rv = mURL->GetPort(&port);
|
||||
|
@ -328,7 +331,7 @@ nsFTPChannel::AsyncOpenAt(nsIStreamListener *listener, nsISupports *ctxt,
|
|||
// Note that ftp doesn't store metadata, so disable caching if there was
|
||||
// an entityID. Storing this metadata isn't worth it until we can
|
||||
// get partial data out of the cache anyway...
|
||||
if (mCacheSession && !mUploadStream && !entityID &&
|
||||
if (mCacheSession && !mUploadStream && entityID.IsEmpty() &&
|
||||
(startPos==0 || startPos==PRUint32(-1))) {
|
||||
mIOService->GetOffline(&offline);
|
||||
|
||||
|
@ -360,7 +363,7 @@ nsFTPChannel::AsyncOpenAt(nsIStreamListener *listener, nsISupports *ctxt,
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsFTPChannel::SetupState(PRUint32 startPos, nsIResumableEntityID* entityID)
|
||||
nsFTPChannel::SetupState(PRUint32 startPos, const nsACString& entityID)
|
||||
{
|
||||
if (!mFTPState) {
|
||||
NS_NEWXPCOM(mFTPState, nsFtpState);
|
||||
|
@ -667,8 +670,9 @@ nsFTPChannel::OnStartRequest(nsIRequest *request, nsISupports *aContext)
|
|||
request->GetStatus(&mStatus);
|
||||
|
||||
nsCOMPtr<nsIResumableChannel> resumable = do_QueryInterface(request);
|
||||
if (resumable)
|
||||
resumable->GetEntityID(getter_AddRefs(mEntityID));
|
||||
if (resumable) {
|
||||
resumable->GetEntityID(mEntityID);
|
||||
}
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (mListener) {
|
||||
|
@ -726,7 +730,7 @@ nsFTPChannel::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry,
|
|||
mCacheEntry = entry;
|
||||
}
|
||||
|
||||
rv = SetupState(PRUint32(-1),nsnull);
|
||||
rv = SetupState(PRUint32(-1), EmptyCString());
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
Cancel(rv);
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsFtpConnectionThread.h"
|
||||
#include "netCore.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIPrompt.h"
|
||||
|
@ -60,7 +59,6 @@
|
|||
#include "nsIUploadChannel.h"
|
||||
#include "nsIProxyInfo.h"
|
||||
#include "nsIResumableChannel.h"
|
||||
#include "nsIResumableEntityID.h"
|
||||
|
||||
#include "nsICacheService.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
|
@ -105,11 +103,11 @@ public:
|
|||
nsIProxyInfo* proxyInfo,
|
||||
nsICacheSession* session);
|
||||
|
||||
nsresult SetupState(PRUint32 startPos, nsIResumableEntityID* entityID);
|
||||
nsresult SetupState(PRUint32 startPos, const nsACString& entityID);
|
||||
nsresult GenerateCacheKey(nsACString &cacheKey);
|
||||
|
||||
nsresult AsyncOpenAt(nsIStreamListener *listener, nsISupports *ctxt,
|
||||
PRUint64 startPos, nsIResumableEntityID* entityID);
|
||||
PRUint64 startPos, const nsACString& entityID);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
|
@ -150,7 +148,7 @@ protected:
|
|||
nsCOMPtr<nsICacheSession> mCacheSession;
|
||||
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;
|
||||
nsCOMPtr<nsIProxyInfo> mProxyInfo;
|
||||
nsCOMPtr<nsIResumableEntityID> mEntityID;
|
||||
nsCString mEntityID;
|
||||
PRUint64 mStartPos;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set tw=80 ts=4 sts=4 sw=4 et cin: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -75,7 +76,6 @@
|
|||
#include "nsICacheListener.h"
|
||||
|
||||
#include "nsIResumableChannel.h"
|
||||
#include "nsIResumableEntityID.h"
|
||||
|
||||
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
||||
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
|
||||
|
@ -128,7 +128,7 @@ public:
|
|||
|
||||
nsresult SetStreamListener(nsIStreamListener *listener);
|
||||
nsresult SetCacheEntry(nsICacheEntryDescriptor *entry, PRBool writing);
|
||||
nsresult SetEntityID(nsIResumableEntityID *entity);
|
||||
nsresult SetEntityID(const nsACString& entity);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
NS_FORWARD_NSICHANNEL(mFTPChannel->)
|
||||
NS_FORWARD_NSIFTPCHANNEL(mFTPChannel->)
|
||||
|
||||
PRUint32 GetBytesTransfered() {return mBytesTransfered;} ;
|
||||
PRUint32 GetBytesTransfered() {return mBytesTransfered;}
|
||||
void Uploading(PRBool value, PRUint32 uploadCount);
|
||||
void SetRetrying(PRBool retry);
|
||||
|
||||
|
@ -151,7 +151,7 @@ protected:
|
|||
nsCOMPtr<nsIStreamListener> mListener;
|
||||
nsCOMPtr<nsIProgressEventSink> mEventSink;
|
||||
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;
|
||||
nsCOMPtr<nsIResumableEntityID> mEntityID;
|
||||
nsCString mEntityID;
|
||||
|
||||
PRUint32 mBytesTransfered;
|
||||
PRUint32 mBytesToUpload;
|
||||
|
@ -258,23 +258,25 @@ DataRequestForwarder::SetStreamListener(nsIStreamListener *listener)
|
|||
}
|
||||
|
||||
nsresult
|
||||
DataRequestForwarder::SetEntityID(nsIResumableEntityID *aEntityID)
|
||||
DataRequestForwarder::SetEntityID(const nsACString& aEntityID)
|
||||
{
|
||||
mEntityID = aEntityID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DataRequestForwarder::GetEntityID(nsIResumableEntityID* *aEntityID)
|
||||
DataRequestForwarder::GetEntityID(nsACString& aEntityID)
|
||||
{
|
||||
*aEntityID = mEntityID;
|
||||
NS_IF_ADDREF(*aEntityID);
|
||||
if (mEntityID.IsEmpty())
|
||||
return NS_ERROR_NOT_RESUMABLE;
|
||||
|
||||
aEntityID = mEntityID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DataRequestForwarder::ResumeAt(PRUint64,
|
||||
nsIResumableEntityID *)
|
||||
const nsACString&)
|
||||
{
|
||||
// We shouldn't get here. This class only exists in the middle of a
|
||||
// request
|
||||
|
@ -431,10 +433,12 @@ nsFtpState::~nsFtpState()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsFtpState::GetEntityID(nsIResumableEntityID** aEntityID)
|
||||
nsFtpState::GetEntityID(nsACString& aEntityID)
|
||||
{
|
||||
*aEntityID = mEntityID;
|
||||
NS_IF_ADDREF(*aEntityID);
|
||||
if (mEntityID.IsEmpty())
|
||||
return NS_ERROR_NOT_RESUMABLE;
|
||||
|
||||
aEntityID = mEntityID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1406,9 +1410,10 @@ nsFtpState::R_mdtm() {
|
|||
}
|
||||
}
|
||||
|
||||
nsresult rv = NS_NewResumableEntityID(getter_AddRefs(mEntityID),
|
||||
mFileSize, mModTime, EmptyCString());
|
||||
if (NS_FAILED(rv)) return FTP_ERROR;
|
||||
mEntityID.Truncate();
|
||||
mEntityID.AppendInt(PRInt64(mFileSize));
|
||||
mEntityID.Append('/');
|
||||
mEntityID.Append(mModTime);
|
||||
mDRequestForwarder->SetEntityID(mEntityID);
|
||||
|
||||
// if we tried downloading this, lets try restarting it...
|
||||
|
@ -1422,10 +1427,9 @@ nsFtpState::R_mdtm() {
|
|||
return FTP_S_RETR;
|
||||
|
||||
//if (our entityID == supplied one (if any))
|
||||
PRBool entEqual = PR_FALSE;
|
||||
if (!mSuppliedEntityID ||
|
||||
(NS_SUCCEEDED(mEntityID->Equals(mSuppliedEntityID, &entEqual)) &&
|
||||
entEqual)) {
|
||||
if (mSuppliedEntityID.IsEmpty() ||
|
||||
mEntityID.Equals(mSuppliedEntityID))
|
||||
{
|
||||
return FTP_S_REST;
|
||||
} else {
|
||||
mInternalError = NS_ERROR_ENTITY_CHANGED;
|
||||
|
@ -1476,16 +1480,16 @@ nsFtpState::S_list() {
|
|||
mDRequestForwarder->SetStreamListener(converter);
|
||||
mDRequestForwarder->SetCacheEntry(mCacheEntry, PR_TRUE);
|
||||
// dir listings aren't resumable
|
||||
NS_ASSERTION(!mSuppliedEntityID,
|
||||
NS_ASSERTION(mSuppliedEntityID.IsEmpty(),
|
||||
"Entity ID given to directory request");
|
||||
NS_ASSERTION(mStartPos == PRUint32(-1) || mStartPos == 0,
|
||||
"Non-intial start position given to directory request");
|
||||
if (mSuppliedEntityID || (mStartPos != PRUint32(-1) && mStartPos != 0)) {
|
||||
"Non-initial start position given to directory request");
|
||||
if (!mSuppliedEntityID.IsEmpty() || (mStartPos != PRUint32(-1) && mStartPos != 0)) {
|
||||
// If we reach this code, then the caller is in error
|
||||
return NS_ERROR_NOT_RESUMABLE;
|
||||
}
|
||||
|
||||
mDRequestForwarder->SetEntityID(nsnull);
|
||||
mDRequestForwarder->SetEntityID(EmptyCString());
|
||||
|
||||
nsCAutoString listString;
|
||||
if (mServerType == FTP_VMS_TYPE)
|
||||
|
@ -1587,7 +1591,7 @@ FTP_STATE
|
|||
nsFtpState::R_rest() {
|
||||
if (mResponseCode/100 == 4) {
|
||||
// If REST fails, then we can't resume
|
||||
mEntityID = nsnull;
|
||||
mEntityID.Truncate();
|
||||
|
||||
mInternalError = NS_ERROR_NOT_RESUMABLE;
|
||||
mResponseMsg.Truncate();
|
||||
|
@ -2150,7 +2154,7 @@ nsFtpState::Init(nsIFTPChannel* aChannel,
|
|||
nsICacheEntryDescriptor* cacheEntry,
|
||||
nsIProxyInfo* proxyInfo,
|
||||
PRUint32 startPos,
|
||||
nsIResumableEntityID* entity)
|
||||
const nsACString& entity)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
@ -2208,7 +2212,7 @@ nsFtpState::Init(nsIFTPChannel* aChannel,
|
|||
|
||||
mDRequestForwarder->SetStreamListener(converter);
|
||||
mDRequestForwarder->SetCacheEntry(mCacheEntry, PR_FALSE);
|
||||
mDRequestForwarder->SetEntityID(nsnull);
|
||||
mDRequestForwarder->SetEntityID(EmptyCString());
|
||||
|
||||
// Get a transport to the cached data...
|
||||
nsCOMPtr<nsIInputStream> input;
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
#include "nsIFTPChannel.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsAutoLock.h"
|
||||
|
@ -61,7 +60,6 @@
|
|||
#include "nsIAuthPrompt.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIProxyInfo.h"
|
||||
#include "nsIResumableEntityID.h"
|
||||
|
||||
#include "nsFtpControlConnection.h"
|
||||
|
||||
|
@ -124,12 +122,12 @@ public:
|
|||
nsICacheEntryDescriptor* cacheEntry,
|
||||
nsIProxyInfo* proxyInfo,
|
||||
PRUint32 startPos,
|
||||
nsIResumableEntityID* entity);
|
||||
const nsACString& entity);
|
||||
|
||||
// use this to provide a stream to be written to the server.
|
||||
nsresult SetWriteStream(nsIInputStream* aInStream);
|
||||
|
||||
nsresult GetEntityID(nsIResumableEntityID* *aEntityID);
|
||||
nsresult GetEntityID(nsACString& aEntityID);
|
||||
|
||||
nsresult Connect();
|
||||
|
||||
|
@ -243,8 +241,8 @@ private:
|
|||
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;
|
||||
|
||||
PRUint32 mStartPos;
|
||||
nsCOMPtr<nsIResumableEntityID> mSuppliedEntityID;
|
||||
nsCOMPtr<nsIResumableEntityID> mEntityID;
|
||||
nsCString mSuppliedEntityID;
|
||||
nsCString mEntityID;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set expandtab ts=4 sw=4 sts=4: */
|
||||
/* vim:set expandtab ts=4 sw=4 sts=4 cin: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -541,19 +541,26 @@ nsHttpChannel::SetupTransaction()
|
|||
PR_snprintf(buf, sizeof(buf), "bytes=%llu-", mStartPos);
|
||||
mRequestHead.SetHeader(nsHttp::Range, nsDependentCString(buf));
|
||||
|
||||
if (mEntityID) {
|
||||
if (!mEntityID.IsEmpty()) {
|
||||
// Also, we want an error if this resource changed in the meantime
|
||||
nsCAutoString entityTag;
|
||||
rv = mEntityID->GetEntityTag(entityTag);
|
||||
if (NS_SUCCEEDED(rv) && !entityTag.IsEmpty()) {
|
||||
mRequestHead.SetHeader(nsHttp::If_Match, entityTag);
|
||||
// Format of the entity id is: escaped_etag/size/lastmod
|
||||
nsCString::const_iterator start, end, slash;
|
||||
mEntityID.BeginReading(start);
|
||||
mEntityID.EndReading(end);
|
||||
mEntityID.BeginReading(slash);
|
||||
|
||||
if (FindCharInReadable('/', slash, end)) {
|
||||
nsCAutoString buf;
|
||||
mRequestHead.SetHeader(nsHttp::If_Match,
|
||||
NS_UnescapeURL(Substring(start, slash), 0, buf));
|
||||
|
||||
++slash; // Incrementing, so that searching for '/' won't find
|
||||
// the same slash again
|
||||
}
|
||||
|
||||
nsCAutoString lastMod;
|
||||
rv = mEntityID->GetLastModified(lastMod);
|
||||
if (NS_SUCCEEDED(rv) && !lastMod.IsEmpty()) {
|
||||
mRequestHead.SetHeader(nsHttp::If_Unmodified_Since, lastMod);
|
||||
|
||||
if (FindCharInReadable('/', slash, end)) {
|
||||
mRequestHead.SetHeader(nsHttp::If_Unmodified_Since,
|
||||
Substring(++slash, end));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -810,17 +817,15 @@ nsHttpChannel::ProcessNormal()
|
|||
// Check that the server sent us what we were asking for
|
||||
if (mResuming) {
|
||||
// Create an entity id from the response
|
||||
nsCOMPtr<nsIResumableEntityID> id;
|
||||
rv = GetEntityID(getter_AddRefs(id));
|
||||
nsCAutoString id;
|
||||
rv = GetEntityID(id);
|
||||
if (NS_FAILED(rv)) {
|
||||
// If creating an entity id is not possible -> error
|
||||
Cancel(NS_ERROR_NOT_RESUMABLE);
|
||||
}
|
||||
// If we were passed an entity id, verify it's equal to the server's
|
||||
else if (mEntityID) {
|
||||
PRBool equal;
|
||||
rv = mEntityID->Equals(id, &equal);
|
||||
if (NS_FAILED(rv) || !equal)
|
||||
else if (!mEntityID.IsEmpty()) {
|
||||
if (!mEntityID.Equals(id))
|
||||
Cancel(NS_ERROR_ENTITY_CHANGED);
|
||||
}
|
||||
}
|
||||
|
@ -3863,7 +3868,7 @@ nsHttpChannel::IsFromCache(PRBool *value)
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsHttpChannel::ResumeAt(PRUint64 aStartPos,
|
||||
nsIResumableEntityID* aEntityID)
|
||||
const nsACString& aEntityID)
|
||||
{
|
||||
mEntityID = aEntityID;
|
||||
mStartPos = aStartPos;
|
||||
|
@ -3872,17 +3877,15 @@ nsHttpChannel::ResumeAt(PRUint64 aStartPos,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHttpChannel::GetEntityID(nsIResumableEntityID** aEntityID)
|
||||
nsHttpChannel::GetEntityID(nsACString& aEntityID)
|
||||
{
|
||||
// Don't return an entity ID for HTTP/1.0 servers
|
||||
if (mResponseHead && (mResponseHead->Version() < NS_HTTP_VERSION_1_1)) {
|
||||
*aEntityID = nsnull;
|
||||
return NS_OK;
|
||||
return NS_ERROR_NOT_RESUMABLE;
|
||||
}
|
||||
// Neither return one for Non-GET requests which require additional data
|
||||
if (mRequestHead.Method() != nsHttp::Get) {
|
||||
*aEntityID = nsnull;
|
||||
return NS_OK;
|
||||
return NS_ERROR_NOT_RESUMABLE;
|
||||
}
|
||||
|
||||
PRUint64 size = LL_MaxUint();
|
||||
|
@ -3896,8 +3899,18 @@ nsHttpChannel::GetEntityID(nsIResumableEntityID** aEntityID)
|
|||
if (cEtag)
|
||||
etag = cEtag;
|
||||
}
|
||||
nsCString entityID;
|
||||
NS_EscapeURL(etag.BeginReading(), etag.Length(), esc_AlwaysCopy |
|
||||
esc_FileBaseName | esc_Forced, entityID);
|
||||
entityID.Append('/');
|
||||
entityID.AppendInt(PRInt64(size));
|
||||
entityID.Append('/');
|
||||
entityID.Append(lastmod);
|
||||
// NOTE: Appending lastmod as the last part avoids having to escape it
|
||||
|
||||
return NS_NewResumableEntityID(aEntityID, size, lastmod, etag);
|
||||
aEntityID = entityID;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -76,7 +76,6 @@ class nsHttpResponseHead;
|
|||
class nsAHttpConnection;
|
||||
class nsIHttpAuthenticator;
|
||||
class nsIProxyInfo;
|
||||
class nsIResumableEntityID;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsHttpChannel
|
||||
|
@ -232,7 +231,7 @@ private:
|
|||
nsHttpAuthIdentity mProxyIdent;
|
||||
|
||||
// Resumable channel specific data
|
||||
nsCOMPtr<nsIResumableEntityID> mEntityID;
|
||||
nsCString mEntityID;
|
||||
PRUint64 mStartPos;
|
||||
|
||||
// redirection specific data.
|
||||
|
|
|
@ -64,7 +64,6 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIResumableChannel.h"
|
||||
#include "nsIResumableEntityID.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
|
@ -104,9 +103,7 @@ static PRBool gAskUserForInput = PR_FALSE;
|
|||
static PRBool gResume = PR_FALSE;
|
||||
static PRUint64 gStartAt = 0;
|
||||
|
||||
static const char* gLastMod = NULL;
|
||||
static const char* gETag = NULL;
|
||||
static PRUint32 gTotalSize = PR_UINT32_MAX;
|
||||
static const char* gEntityID = NULL;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Set proxy preferences for testing
|
||||
|
@ -417,27 +414,13 @@ InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
|||
nsCOMPtr<nsIResumableChannel> resChannel = do_QueryInterface(request);
|
||||
if (resChannel) {
|
||||
LOG(("Resumable entity identification:\n"));
|
||||
nsCOMPtr<nsIResumableEntityID> entityID;
|
||||
nsresult rv = resChannel->GetEntityID(getter_AddRefs(entityID));
|
||||
if (NS_SUCCEEDED(rv) && entityID) {
|
||||
PRUint64 size;
|
||||
if (NS_SUCCEEDED(entityID->GetSize(&size)) &&
|
||||
LL_NE(size, LL_MaxUint()))
|
||||
LOG(("\tSize: %llu\n", size));
|
||||
else
|
||||
LOG(("\tSize: Unknown\n"));
|
||||
nsCAutoString lastModified;
|
||||
if (NS_SUCCEEDED(entityID->GetLastModified(lastModified)) &&
|
||||
!lastModified.IsEmpty())
|
||||
LOG(("\tLast Modified: %s\n", lastModified.get()));
|
||||
else
|
||||
LOG(("\tLast Modified: Unknown\n"));
|
||||
nsCAutoString etag;
|
||||
if (NS_SUCCEEDED(entityID->GetEntityTag(etag)) &&
|
||||
!etag.IsEmpty())
|
||||
LOG(("\tETag: %s\n", etag.get()));
|
||||
else
|
||||
LOG(("\tEtag: Unknown\n"));
|
||||
nsCAutoString entityID;
|
||||
nsresult rv = resChannel->GetEntityID(entityID);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LOG(("\t|%s|\n", entityID.get()));
|
||||
}
|
||||
else {
|
||||
LOG(("\t<none>\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,20 +647,10 @@ nsresult StartLoadingURL(const char* aUrlString)
|
|||
NS_ERROR("Channel is not resumable!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
nsCOMPtr<nsIResumableEntityID> id;
|
||||
if (gETag || gLastMod || gTotalSize != PR_UINT32_MAX) {
|
||||
id = do_CreateInstance(NS_RESUMABLEENTITYID_CONTRACTID);
|
||||
if (!id) {
|
||||
fprintf(stderr, "Error creating entityid\n");
|
||||
}
|
||||
else {
|
||||
if (gETag)
|
||||
id->SetEntityTag(nsDependentCString(gETag));
|
||||
if (gLastMod)
|
||||
id->SetLastModified(nsDependentCString(gLastMod));
|
||||
id->SetSize(gTotalSize);
|
||||
}
|
||||
}
|
||||
nsCAutoString id;
|
||||
if (gEntityID)
|
||||
id = gEntityID;
|
||||
LOG(("* resuming at %llu bytes, with entity id |%s|\n", gStartAt, id.get()));
|
||||
res->ResumeAt(gStartAt, id);
|
||||
}
|
||||
rv = pChannel->AsyncOpen(listener, // IStreamListener consumer
|
||||
|
@ -759,7 +732,7 @@ main(int argc, char* argv[])
|
|||
{
|
||||
nsresult rv= (nsresult)-1;
|
||||
if (argc < 2) {
|
||||
printf("usage: %s [-verbose] [-file <name>] [-resume <startoffset> [-etag <etag>] [-lastmod <lastmod (string)>] [-totalsize <size>] [-proxy <proxy>] [-console] <url> <url> ... \n", argv[0]);
|
||||
printf("usage: %s [-verbose] [-file <name>] [-resume <startoffset> [-entityid <entityid>]] [-proxy <proxy>] [-console] <url> <url> ... \n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -809,18 +782,8 @@ main(int argc, char* argv[])
|
|||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-etag") == 0) {
|
||||
gETag = argv[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-lastmod") == 0) {
|
||||
gLastMod = argv[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PL_strcasecmp(argv[i], "-totalsize") == 0) {
|
||||
gTotalSize = atoi(argv[++i]);
|
||||
if (PL_strcasecmp(argv[i], "-entityid") == 0) {
|
||||
gEntityID = argv[++i];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче