2001-05-11 21:04:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications. Portions created by Netscape Communications are
|
|
|
|
* Copyright (C) 2001 by Netscape Communications. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Darin Fisher <darin@netscape.com> (original author)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsHttpTransaction_h__
|
|
|
|
#define nsHttpTransaction_h__
|
|
|
|
|
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsHttpHeaderArray.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-06-11 21:20:29 +00:00
|
|
|
#include "nsIEventQueue.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
class nsHttpRequestHead;
|
|
|
|
class nsHttpResponseHead;
|
|
|
|
class nsHttpConnection;
|
|
|
|
class nsHttpChunkedDecoder;
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpTransaction represents a single HTTP transaction. It is thread-safe,
|
|
|
|
// intended to run on the socket thread.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsHttpTransaction : public nsIRequest
|
|
|
|
, public nsIInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
|
|
|
|
// A transaction is constructed from request headers.
|
|
|
|
nsHttpTransaction(nsIStreamListener *, nsIInterfaceRequestor *);
|
|
|
|
virtual ~nsHttpTransaction();
|
|
|
|
|
|
|
|
nsrefcnt RefCnt() { return mRefCnt; }
|
|
|
|
|
|
|
|
// Called when assigned to a connection
|
|
|
|
nsresult SetConnection(nsHttpConnection *);
|
|
|
|
|
2001-06-14 20:52:03 +00:00
|
|
|
// Called by the connection to set the associated socket security info
|
|
|
|
void SetSecurityInfo(nsISupports *info) { mSecurityInfo = info; }
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// Called to initialize the transaction
|
|
|
|
nsresult SetupRequest(nsHttpRequestHead *, nsIInputStream *);
|
|
|
|
|
2001-06-11 21:20:29 +00:00
|
|
|
nsIStreamListener *Listener() { return mListener; }
|
|
|
|
nsHttpConnection *Connection() { return mConnection; }
|
|
|
|
nsHttpRequestHead *RequestHead() { return mRequestHead; }
|
2001-08-02 19:26:24 +00:00
|
|
|
nsHttpResponseHead *ResponseHead() { return mHaveAllHeaders ? mResponseHead : nsnull; }
|
2001-06-11 21:20:29 +00:00
|
|
|
nsIInterfaceRequestor *Callbacks() { return mCallbacks; }
|
|
|
|
nsIEventQueue *ConsumerEventQ() { return mConsumerEventQ; }
|
2001-06-14 20:52:03 +00:00
|
|
|
nsISupports *SecurityInfo() { return mSecurityInfo; }
|
2001-06-20 01:21:43 +00:00
|
|
|
PRBool IsDone() { return mTransactionDone; }
|
|
|
|
nsresult Status() { return mStatus; }
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// Called to take ownership of the response headers; the transaction
|
|
|
|
// will drop any reference to the response headers after this call.
|
|
|
|
nsHttpResponseHead *TakeResponseHead();
|
|
|
|
|
|
|
|
// Called to write data to the socket until return NS_BASE_STREAM_CLOSED
|
|
|
|
nsresult OnDataWritable(nsIOutputStream *);
|
|
|
|
|
|
|
|
// Called to read data from the socket buffer
|
|
|
|
nsresult OnDataReadable(nsIInputStream *);
|
|
|
|
|
|
|
|
// Called when the transaction should stop, possibly prematurely with an error.
|
|
|
|
nsresult OnStopTransaction(nsresult);
|
|
|
|
|
|
|
|
private:
|
2001-08-02 19:26:24 +00:00
|
|
|
void ParseLine(char *line);
|
|
|
|
void ParseLineSegment(char *seg, PRUint32 len);
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult ParseHead(char *, PRUint32 count, PRUint32 *countRead);
|
2001-06-13 22:44:47 +00:00
|
|
|
nsresult HandleContentStart();
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult HandleContent(char *, PRUint32 count, PRUint32 *countRead);
|
2001-06-11 21:20:29 +00:00
|
|
|
void DeleteSelfOnConsumerThread();
|
|
|
|
|
|
|
|
static void *PR_CALLBACK DeleteThis_EventHandlerFunc(PLEvent *);
|
|
|
|
static void PR_CALLBACK DeleteThis_EventCleanupFunc(PLEvent *);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
2001-06-11 21:20:29 +00:00
|
|
|
nsCOMPtr<nsIEventQueue> mConsumerEventQ;
|
2001-06-14 20:52:03 +00:00
|
|
|
nsCOMPtr<nsISupports> mSecurityInfo;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
nsHttpConnection *mConnection; // hard ref
|
|
|
|
|
|
|
|
nsCString mReqHeaderBuf; // flattened request headers
|
|
|
|
nsCOMPtr<nsIInputStream> mReqHeaderStream; // header data stream
|
|
|
|
nsCOMPtr<nsIInputStream> mReqUploadStream; // upload data stream
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> mSource;
|
2001-05-30 00:40:50 +00:00
|
|
|
nsHttpRequestHead *mRequestHead; // weak ref
|
|
|
|
nsHttpResponseHead *mResponseHead; // hard ref
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
nsCString mLineBuf; // may contain a partial line
|
|
|
|
|
|
|
|
PRInt32 mContentLength; // equals -1 if unknown
|
|
|
|
PRUint32 mContentRead; // count of consumed content bytes
|
|
|
|
|
|
|
|
nsHttpChunkedDecoder *mChunkedDecoder;
|
|
|
|
|
|
|
|
PRInt32 mTransactionDone; // set atomically
|
|
|
|
nsresult mStatus;
|
|
|
|
|
|
|
|
PRPackedBool mHaveStatusLine;
|
|
|
|
PRPackedBool mHaveAllHeaders;
|
|
|
|
PRPackedBool mFiredOnStart;
|
|
|
|
PRPackedBool mNoContent; // true if we're expecting an empty entity body
|
2001-05-25 23:18:50 +00:00
|
|
|
PRPackedBool mPrematureEOF;
|
2001-05-11 21:04:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsHttpTransaction_h__
|