Cleanup - Moved the PostData stream from the nsHTTPChannel to the nsHTTPRequest... The PostStream is now released once the request has been sent to the server since it is no longer useful. Fixed up Cancel to remove the channel from the list of pending requests if necessary.

This commit is contained in:
rpotts%netscape.com 1999-10-26 04:48:26 +00:00
Родитель 8603fffaf1
Коммит 5a4bbbd3b8
4 изменённых файлов: 127 добавлений и 85 удалений

Просмотреть файл

@ -70,7 +70,6 @@ nsHTTPChannel::nsHTTPChannel(nsIURI* i_URL,
mLoadAttributes(LOAD_NORMAL),
mResponseContext(nsnull),
mLoadGroup(nsnull),
mPostStream(nsnull),
mAuthTriedWithPrehost(PR_FALSE),
mUsingProxy(PR_FALSE)
{
@ -104,7 +103,6 @@ nsHTTPChannel::~nsHTTPChannel()
//TODO if we keep our copy of mURI, then delete it too.
NS_IF_RELEASE(mRequest);
NS_IF_RELEASE(mResponse);
NS_IF_RELEASE(mPostStream);
NS_IF_RELEASE(mResponseDataListener);
mHandler = null_nsCOMPtr();
@ -140,10 +138,12 @@ NS_IMPL_RELEASE(nsHTTPChannel);
NS_IMETHODIMP
nsHTTPChannel::IsPending(PRBool *result)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv;
if (mRequest) {
rv = mRequest->IsPending(result);
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
@ -151,10 +151,20 @@ nsHTTPChannel::IsPending(PRBool *result)
NS_IMETHODIMP
nsHTTPChannel::Cancel(void)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv;
//
// If this channel is currently waiting for a transport to become available.
// Notify the HTTPHandler that this request has been cancelled...
//
if (!mConnected && (HS_WAITING_FOR_OPEN == mState)) {
rv = mHandler->CancelPendingChannel(this);
}
if (mRequest) {
rv = mRequest->Cancel();
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
@ -162,10 +172,12 @@ nsHTTPChannel::Cancel(void)
NS_IMETHODIMP
nsHTTPChannel::Suspend(void)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv;
if (mRequest) {
rv = mRequest->Suspend();
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
@ -173,10 +185,12 @@ nsHTTPChannel::Suspend(void)
NS_IMETHODIMP
nsHTTPChannel::Resume(void)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv;
if (mRequest) {
rv = mRequest->Resume();
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
@ -297,7 +311,7 @@ nsHTTPChannel::GetContentType(char * *aContentType)
*aContentType = nsnull;
//
// If the content type has been returned by the server then retern that...
// If the content type has been returned by the server then return that...
//
if (mContentType.Length()) {
*aContentType = mContentType.ToNewCString();
@ -493,6 +507,53 @@ nsHTTPChannel::GetCharset(char* *o_String)
return rv;
}
NS_IMETHODIMP
nsHTTPChannel::SetPostDataStream(nsIInputStream* aPostStream)
{
nsresult rv = NS_OK;
if (aPostStream && mRequest) {
rv = mRequest->SetPostDataStream(aPostStream);
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
NS_IMETHODIMP
nsHTTPChannel::GetPostDataStream(nsIInputStream **o_postStream)
{
nsresult rv = NS_OK;
if (o_postStream && mRequest) {
rv = mRequest->GetPostDataStream(o_postStream);
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
NS_IMETHODIMP
nsHTTPChannel::SetAuthTriedWithPrehost(PRBool iTried)
{
mAuthTriedWithPrehost = iTried;
return NS_OK;
}
NS_IMETHODIMP
nsHTTPChannel::GetAuthTriedWithPrehost(PRBool* oTried)
{
if (oTried)
{
*oTried = mAuthTriedWithPrehost;
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kProxyObjectManagerIID, NS_IPROXYEVENT_MANAGER_IID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
@ -582,6 +643,7 @@ nsHTTPChannel::Open(void)
mState = HS_WAITING_FOR_OPEN;
return NS_OK;
}
if (NS_FAILED(rv)) return rv;
// Check for any modules that want to set headers before we
// send out a request.
@ -792,48 +854,6 @@ nsresult nsHTTPChannel::SetCharset(const char *aCharset)
}
nsresult
nsHTTPChannel::SetPostDataStream(nsIInputStream* postDataStream)
{
NS_IF_RELEASE(mPostStream);
mPostStream = postDataStream;
if (mPostStream)
NS_ADDREF(mPostStream);
return NS_OK;
}
nsresult
nsHTTPChannel::GetPostDataStream(nsIInputStream **o_postStream)
{
if (o_postStream)
{
*o_postStream = mPostStream;
NS_IF_ADDREF(*o_postStream);
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsHTTPChannel::SetAuthTriedWithPrehost(PRBool iTried)
{
mAuthTriedWithPrehost = iTried;
return NS_OK;
}
NS_IMETHODIMP
nsHTTPChannel::GetAuthTriedWithPrehost(PRBool* oTried)
{
if (oTried)
{
*oTried = mAuthTriedWithPrehost;
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult
nsHTTPChannel::Authenticate(const char *iChallenge, nsIChannel **oChannel)
{

Просмотреть файл

@ -101,7 +101,6 @@ protected:
PRInt32 mContentLength;
nsCString mContentType;
nsCString mCharset;
nsIInputStream* mPostStream;
nsCOMPtr<nsISupports> mOwner;
// Auth related stuff-
/*

Просмотреть файл

@ -91,6 +91,9 @@ nsHTTPRequest::~nsHTTPRequest()
*/
}
////////////////////////////////////////////////////////////////////////////////
// nsISupports methods:
NS_IMPL_ADDREF(nsHTTPRequest);
NS_IMPL_RELEASE(nsHTTPRequest);
@ -124,18 +127,21 @@ nsHTTPRequest::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_IMETHODIMP
nsHTTPRequest::IsPending(PRBool *result)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv = NS_OK;
if (mTransport) {
rv = mTransport->IsPending(result);
} else {
*result = PR_FALSE;
}
return rv;
}
NS_IMETHODIMP
nsHTTPRequest::Cancel(void)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv = NS_ERROR_FAILURE;
if (mTransport) {
rv = mTransport->Cancel();
@ -146,7 +152,7 @@ nsHTTPRequest::Cancel(void)
NS_IMETHODIMP
nsHTTPRequest::Suspend(void)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv = NS_ERROR_FAILURE;
if (mTransport) {
rv = mTransport->Suspend();
@ -157,7 +163,7 @@ nsHTTPRequest::Suspend(void)
NS_IMETHODIMP
nsHTTPRequest::Resume(void)
{
nsresult rv = NS_ERROR_NULL_POINTER;
nsresult rv = NS_ERROR_FAILURE;
if (mTransport) {
rv = mTransport->Resume();
@ -320,66 +326,80 @@ nsresult nsHTTPRequest::WriteRequest(nsIChannel *aTransport, PRBool aIsProxied)
return rv;
}
NS_METHOD
nsHTTPRequest::Clone(const nsHTTPRequest* *o_Request) const
nsresult nsHTTPRequest::Clone(const nsHTTPRequest* *o_Request) const
{
return NS_ERROR_FAILURE;
}
NS_METHOD
nsHTTPRequest::SetMethod(HTTPMethod i_Method)
nsresult nsHTTPRequest::SetMethod(HTTPMethod i_Method)
{
mMethod = i_Method;
return NS_OK;
}
HTTPMethod
nsHTTPRequest::GetMethod(void) const
HTTPMethod nsHTTPRequest::GetMethod(void) const
{
return mMethod;
}
NS_METHOD
nsHTTPRequest::SetPriority()
nsresult nsHTTPRequest::SetPriority()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_METHOD
nsHTTPRequest::GetPriority()
nsresult nsHTTPRequest::GetPriority()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_METHOD
nsHTTPRequest::SetHeader(nsIAtom* i_Header, const char* i_Value)
nsresult nsHTTPRequest::SetHeader(nsIAtom* i_Header, const char* i_Value)
{
return mHeaders.SetHeader(i_Header, i_Value);
}
NS_METHOD
nsHTTPRequest::GetHeader(nsIAtom* i_Header, char* *o_Value)
nsresult nsHTTPRequest::GetHeader(nsIAtom* i_Header, char* *o_Value)
{
return mHeaders.GetHeader(i_Header, o_Value);
}
NS_METHOD
nsHTTPRequest::SetHTTPVersion(HTTPVersion i_Version)
nsresult nsHTTPRequest::SetHTTPVersion(HTTPVersion i_Version)
{
mVersion = i_Version;
return NS_OK;
}
NS_METHOD
nsHTTPRequest::GetHTTPVersion(HTTPVersion* o_Version)
nsresult nsHTTPRequest::GetHTTPVersion(HTTPVersion* o_Version)
{
*o_Version = mVersion;
return NS_OK;
}
nsresult nsHTTPRequest::SetPostDataStream(nsIInputStream* aStream)
{
mPostDataStream = aStream;
return NS_OK;
}
nsresult nsHTTPRequest::GetPostDataStream(nsIInputStream* *aResult)
{
nsresult rv = NS_OK;
if (aResult) {
*aResult = mPostDataStream;
NS_IF_ADDREF(*aResult);
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIStreamObserver methods:
NS_IMETHODIMP
nsHTTPRequest::OnStartRequest(nsIChannel* channel, nsISupports* i_Context)
@ -474,8 +494,7 @@ nsHTTPRequest::OnStopRequest(nsIChannel* channel, nsISupports* i_Context,
}
NS_IMETHODIMP
nsHTTPRequest::SetConnection(nsHTTPChannel* i_Connection)
nsresult nsHTTPRequest::SetConnection(nsHTTPChannel* i_Connection)
{
mConnection = i_Connection;
return NS_OK;

Просмотреть файл

@ -59,9 +59,8 @@ class nsHTTPRequest : public nsIStreamObserver,
public:
// Constructor and destructor
// Constructor
nsHTTPRequest(nsIURI* i_URL=0, HTTPMethod i_Method=HM_GET, nsIChannel* i_Tranport = nsnull);
virtual ~nsHTTPRequest();
NS_DECL_ISUPPORTS
NS_DECL_NSISTREAMOBSERVER
@ -79,33 +78,38 @@ public:
Similarly getting will for now only get the first occurence.
TODO change to get the list.
*/
NS_IMETHOD SetHeader(nsIAtom* i_Header, const char* i_Value);
NS_IMETHOD GetHeader(nsIAtom* i_Header, char* *o_Value);
nsresult SetHeader(nsIAtom* i_Header, const char* i_Value);
nsresult GetHeader(nsIAtom* i_Header, char* *o_Value);
/*
Clone the current request for later use. Release it
after you are done.
*/
NS_IMETHOD Clone(const nsHTTPRequest* *o_Copy) const;
nsresult Clone(const nsHTTPRequest* *o_Copy) const;
NS_IMETHOD SetHTTPVersion(HTTPVersion i_Version);
NS_IMETHOD GetHTTPVersion(HTTPVersion* o_Version);
nsresult SetHTTPVersion(HTTPVersion i_Version);
nsresult GetHTTPVersion(HTTPVersion* o_Version);
NS_IMETHOD SetMethod(HTTPMethod i_Method);
nsresult SetMethod(HTTPMethod i_Method);
HTTPMethod GetMethod(void) const;
NS_IMETHOD SetPriority(); // TODO
NS_IMETHOD GetPriority(); //TODO
nsresult SetPriority(); // TODO
nsresult GetPriority(); //TODO
nsresult GetHeaderEnumerator(nsISimpleEnumerator** aResult);
NS_IMETHOD SetConnection(nsHTTPChannel* i_Connection);
nsresult SetConnection(nsHTTPChannel* i_Connection);
// Build the actual request string based on the settings.
nsresult WriteRequest(nsIChannel *aChannel,
PRBool aIsProxied = PR_FALSE);
nsresult GetPostDataStream(nsIInputStream* *aResult);
nsresult SetPostDataStream(nsIInputStream* aStream);
protected:
virtual ~nsHTTPRequest();
// Use a method string corresponding to the method.
const char* MethodToString(HTTPMethod i_Method=HM_GET)
{