2001-05-12 01:04:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-19 02:01:16 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2001-05-12 01:04:09 +04:00
|
|
|
* The Original Code is Mozilla.
|
2004-04-19 02:01:16 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-05-12 01:04:09 +04:00
|
|
|
* Darin Fisher <darin@netscape.com> (original author)
|
2004-04-19 02:01:16 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-05-12 01:04:09 +04:00
|
|
|
|
|
|
|
#ifndef nsHttpTransaction_h__
|
|
|
|
#define nsHttpTransaction_h__
|
|
|
|
|
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsHttpHeaderArray.h"
|
2001-10-02 04:31:30 +04:00
|
|
|
#include "nsAHttpTransaction.h"
|
|
|
|
#include "nsAHttpConnection.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsIPipe.h"
|
2001-05-12 01:04:09 +04:00
|
|
|
#include "nsIInputStream.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsIOutputStream.h"
|
2001-05-12 01:04:09 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsISocketTransportService.h"
|
|
|
|
#include "nsITransport.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsIEventTarget.h"
|
2011-05-21 14:03:36 +04:00
|
|
|
#include "TimingStruct.h"
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsHttpTransaction;
|
2001-05-12 01:04:09 +04:00
|
|
|
class nsHttpRequestHead;
|
|
|
|
class nsHttpResponseHead;
|
|
|
|
class nsHttpChunkedDecoder;
|
2006-05-20 02:50:02 +04:00
|
|
|
class nsIHttpActivityObserver;
|
2001-05-12 01:04:09 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpTransaction represents a single HTTP transaction. It is thread-safe,
|
|
|
|
// intended to run on the socket thread.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-10-02 04:31:30 +04:00
|
|
|
class nsHttpTransaction : public nsAHttpTransaction
|
2003-10-08 10:10:47 +04:00
|
|
|
, public nsIInputStreamCallback
|
2003-10-06 05:46:31 +04:00
|
|
|
, public nsIOutputStreamCallback
|
2001-05-12 01:04:09 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2003-03-26 08:05:49 +03:00
|
|
|
NS_DECL_NSAHTTPTRANSACTION
|
2003-10-08 10:10:47 +04:00
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
2003-10-06 05:46:31 +04:00
|
|
|
NS_DECL_NSIOUTPUTSTREAMCALLBACK
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsHttpTransaction();
|
2001-05-12 01:04:09 +04:00
|
|
|
virtual ~nsHttpTransaction();
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//
|
|
|
|
// called to initialize the transaction
|
|
|
|
//
|
|
|
|
// @param caps
|
|
|
|
// the transaction capabilities (see nsHttp.h)
|
|
|
|
// @param connInfo
|
|
|
|
// the connection type for this transaction.
|
|
|
|
// @param reqHeaders
|
|
|
|
// the request header struct
|
|
|
|
// @param reqBody
|
|
|
|
// the request body (POST or PUT data stream)
|
|
|
|
// @param reqBodyIncludesHeaders
|
|
|
|
// fun stuff to support NPAPI plugins.
|
2006-05-10 21:30:15 +04:00
|
|
|
// @param target
|
|
|
|
// the dispatch target were notifications should be sent.
|
2003-01-18 05:15:14 +03:00
|
|
|
// @param callbacks
|
|
|
|
// the notification callbacks to be given to PSM.
|
|
|
|
// @param responseBody
|
|
|
|
// the input stream that will contain the response data. async
|
|
|
|
// wait on this input stream for data. on first notification,
|
|
|
|
// headers should be available (check transaction status).
|
|
|
|
//
|
|
|
|
nsresult Init(PRUint8 caps,
|
|
|
|
nsHttpConnectionInfo *connInfo,
|
|
|
|
nsHttpRequestHead *reqHeaders,
|
|
|
|
nsIInputStream *reqBody,
|
|
|
|
PRBool reqBodyIncludesHeaders,
|
2006-05-10 21:30:15 +04:00
|
|
|
nsIEventTarget *consumerTarget,
|
2003-01-18 05:15:14 +03:00
|
|
|
nsIInterfaceRequestor *callbacks,
|
|
|
|
nsITransportEventSink *eventsink,
|
|
|
|
nsIAsyncInputStream **responseBody);
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
PRUint8 Caps() { return mCaps; }
|
|
|
|
nsHttpConnectionInfo *ConnectionInfo() { return mConnInfo; }
|
2001-08-02 23:26:24 +04:00
|
|
|
nsHttpResponseHead *ResponseHead() { return mHaveAllHeaders ? mResponseHead : nsnull; }
|
2003-01-18 05:15:14 +03:00
|
|
|
nsISupports *SecurityInfo() { return mSecurityInfo; }
|
|
|
|
|
2001-06-12 01:20:29 +04:00
|
|
|
nsIInterfaceRequestor *Callbacks() { return mCallbacks; }
|
2006-05-10 21:30:15 +04:00
|
|
|
nsIEventTarget *ConsumerTarget() { return mConsumerTarget; }
|
2003-01-18 05:15:14 +03:00
|
|
|
nsAHttpConnection *Connection() { return mConnection; }
|
2001-05-12 01:04:09 +04:00
|
|
|
|
|
|
|
// Called to take ownership of the response headers; the transaction
|
|
|
|
// will drop any reference to the response headers after this call.
|
|
|
|
nsHttpResponseHead *TakeResponseHead();
|
|
|
|
|
2002-03-27 02:33:19 +03:00
|
|
|
// Called to find out if the transaction generated a complete response.
|
|
|
|
PRBool ResponseIsComplete() { return mResponseIsComplete; }
|
|
|
|
|
2004-11-06 04:35:01 +03:00
|
|
|
PRBool SSLConnectFailed() { return mSSLConnectFailed; }
|
|
|
|
|
2005-01-15 10:01:20 +03:00
|
|
|
// These methods may only be used by the connection manager.
|
|
|
|
void SetPriority(PRInt32 priority) { mPriority = priority; }
|
|
|
|
PRInt32 Priority() { return mPriority; }
|
|
|
|
|
2011-05-21 14:03:36 +04:00
|
|
|
const TimingStruct& Timings() const { return mTimings; }
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
private:
|
2001-09-21 07:59:02 +04:00
|
|
|
nsresult Restart();
|
2010-12-01 03:02:52 +03:00
|
|
|
char *LocateHttpStart(char *buf, PRUint32 len,
|
|
|
|
PRBool aAllowPartialMatch);
|
2011-06-01 03:51:51 +04:00
|
|
|
nsresult ParseLine(char *line);
|
2002-08-27 06:26:43 +04:00
|
|
|
nsresult ParseLineSegment(char *seg, PRUint32 len);
|
2001-05-12 01:04:09 +04:00
|
|
|
nsresult ParseHead(char *, PRUint32 count, PRUint32 *countRead);
|
2001-06-14 02:44:47 +04:00
|
|
|
nsresult HandleContentStart();
|
2002-06-18 01:08:46 +04:00
|
|
|
nsresult HandleContent(char *, PRUint32 count, PRUint32 *contentRead, PRUint32 *contentRemaining);
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult ProcessData(char *, PRUint32, PRUint32 *);
|
2001-06-12 01:20:29 +04:00
|
|
|
void DeleteSelfOnConsumerThread();
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
static NS_METHOD ReadRequestSegment(nsIInputStream *, void *, const char *,
|
|
|
|
PRUint32, PRUint32, PRUint32 *);
|
|
|
|
static NS_METHOD WritePipeSegment(nsIOutputStream *, void *, char *,
|
|
|
|
PRUint32, PRUint32, PRUint32 *);
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2011-05-21 14:03:36 +04:00
|
|
|
PRBool TimingEnabled() const { return mCaps & NS_HTTP_TIMING_ENABLED; }
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsITransportEventSink> mTransportSink;
|
2006-05-10 21:30:15 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> mConsumerTarget;
|
2001-06-15 00:52:03 +04:00
|
|
|
nsCOMPtr<nsISupports> mSecurityInfo;
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIAsyncInputStream> mPipeIn;
|
|
|
|
nsCOMPtr<nsIAsyncOutputStream> mPipeOut;
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2006-05-20 02:50:02 +04:00
|
|
|
nsCOMPtr<nsISupports> mChannel;
|
|
|
|
nsCOMPtr<nsIHttpActivityObserver> mActivityDistributor;
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
nsCString mReqHeaderBuf; // flattened request headers
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIInputStream> mRequestStream;
|
|
|
|
PRUint32 mRequestSize;
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsAHttpConnection *mConnection; // hard ref
|
|
|
|
nsHttpConnectionInfo *mConnInfo; // hard ref
|
2001-05-30 04:40:50 +04:00
|
|
|
nsHttpRequestHead *mRequestHead; // weak ref
|
|
|
|
nsHttpResponseHead *mResponseHead; // hard ref
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsAHttpSegmentReader *mReader;
|
|
|
|
nsAHttpSegmentWriter *mWriter;
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
nsCString mLineBuf; // may contain a partial line
|
|
|
|
|
2011-04-01 04:15:27 +04:00
|
|
|
PRInt64 mContentLength; // equals -1 if unknown
|
|
|
|
PRInt64 mContentRead; // count of consumed content bytes
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2011-01-27 21:34:39 +03:00
|
|
|
// After a 304/204 or other "no-content" style response we will skip over
|
|
|
|
// up to MAX_INVALID_RESPONSE_BODY_SZ bytes when looking for the next
|
|
|
|
// response header to deal with servers that actually sent a response
|
|
|
|
// body where they should not have. This member tracks how many bytes have
|
|
|
|
// so far been skipped.
|
|
|
|
PRUint32 mInvalidResponseBytesRead;
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
nsHttpChunkedDecoder *mChunkedDecoder;
|
|
|
|
|
2011-05-21 14:03:36 +04:00
|
|
|
TimingStruct mTimings;
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
nsresult mStatus;
|
|
|
|
|
2005-01-15 10:01:20 +03:00
|
|
|
PRInt16 mPriority;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
PRUint16 mRestartCount; // the number of times this transaction has been restarted
|
|
|
|
PRUint8 mCaps;
|
2001-08-14 05:03:27 +04:00
|
|
|
|
2011-03-24 22:51:00 +03:00
|
|
|
// state flags, all logically boolean, but not packed together into a
|
|
|
|
// bitfield so as to avoid bitfield-induced races. See bug 560579.
|
|
|
|
PRPackedBool mClosed;
|
|
|
|
PRPackedBool mConnected;
|
|
|
|
PRPackedBool mHaveStatusLine;
|
|
|
|
PRPackedBool mHaveAllHeaders;
|
|
|
|
PRPackedBool mTransactionDone;
|
|
|
|
PRPackedBool mResponseIsComplete;
|
|
|
|
PRPackedBool mDidContentStart;
|
|
|
|
PRPackedBool mNoContent; // expecting an empty entity body
|
|
|
|
PRPackedBool mSentData;
|
|
|
|
PRPackedBool mReceivedData;
|
|
|
|
PRPackedBool mStatusEventPending;
|
|
|
|
PRPackedBool mHasRequestBody;
|
|
|
|
PRPackedBool mSSLConnectFailed;
|
|
|
|
PRPackedBool mHttpResponseMatched;
|
2011-05-20 03:43:37 +04:00
|
|
|
PRPackedBool mPreserveStream;
|
2003-03-25 05:23:11 +03:00
|
|
|
|
|
|
|
// mClosed := transaction has been explicitly closed
|
|
|
|
// mTransactionDone := transaction ran to completion or was interrupted
|
|
|
|
// mResponseComplete := transaction ran to completion
|
2001-05-12 01:04:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsHttpTransaction_h__
|