netwerk/protocol/http/nsAHttpConnection.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsAHttpConnection_h__
     6 #define nsAHttpConnection_h__
     8 #include "nsISupports.h"
     9 #include "nsAHttpTransaction.h"
    11 class nsISocketTransport;
    12 class nsIAsyncInputStream;
    13 class nsIAsyncOutputStream;
    15 namespace mozilla { namespace net {
    17 class nsHttpConnectionInfo;
    18 class nsHttpConnection;
    20 //-----------------------------------------------------------------------------
    21 // Abstract base class for a HTTP connection
    22 //-----------------------------------------------------------------------------
    24 class nsAHttpConnection : public nsISupports
    25 {
    26 public:
    27     //-------------------------------------------------------------------------
    28     // NOTE: these methods may only be called on the socket thread.
    29     //-------------------------------------------------------------------------
    31     //
    32     // called by a transaction when the response headers have all been read.
    33     // the connection can force the transaction to reset it's response headers,
    34     // and prepare for a new set of response headers, by setting |*reset=TRUE|.
    35     //
    36     // @return failure code to close the transaction.
    37     //
    38     virtual nsresult OnHeadersAvailable(nsAHttpTransaction *,
    39                                         nsHttpRequestHead *,
    40                                         nsHttpResponseHead *,
    41                                         bool *reset) = 0;
    43     //
    44     // called by a transaction to resume either sending or receiving data
    45     // after a transaction returned NS_BASE_STREAM_WOULD_BLOCK from its
    46     // ReadSegments/WriteSegments methods.
    47     //
    48     virtual nsresult ResumeSend() = 0;
    49     virtual nsresult ResumeRecv() = 0;
    51     // called by a transaction to force a "read from network" iteration
    52     // even if not scheduled by socket associated with connection
    53     virtual nsresult ForceRecv() = 0;
    55     // After a connection has had ResumeSend() called by a transaction,
    56     // and it is ready to write to the network it may need to know the
    57     // transaction that has data to write. This is only an issue for
    58     // multiplexed protocols like SPDY - plain HTTP or pipelined HTTP
    59     // implicitly have this information in a 1:1 relationship with the
    60     // transaction(s) they manage.
    61     virtual void TransactionHasDataToWrite(nsAHttpTransaction *)
    62     {
    63         // by default do nothing - only multiplexed protocols need to overload
    64         return;
    65     }
    66     //
    67     // called by the connection manager to close a transaction being processed
    68     // by this connection.
    69     //
    70     // @param transaction
    71     //        the transaction being closed.
    72     // @param reason
    73     //        the reason for closing the transaction.  NS_BASE_STREAM_CLOSED
    74     //        is equivalent to NS_OK.
    75     //
    76     virtual void CloseTransaction(nsAHttpTransaction *transaction,
    77                                   nsresult reason) = 0;
    79     // get a reference to the connection's connection info object.
    80     virtual void GetConnectionInfo(nsHttpConnectionInfo **) = 0;
    82     // get the transport level information for this connection. This may fail
    83     // if it is in use.
    84     virtual nsresult TakeTransport(nsISocketTransport **,
    85                                    nsIAsyncInputStream **,
    86                                    nsIAsyncOutputStream **) = 0;
    88     // called by a transaction to get the security info from the socket.
    89     virtual void GetSecurityInfo(nsISupports **) = 0;
    91     // called by a transaction to determine whether or not the connection is
    92     // persistent... important in determining the end of a response.
    93     virtual bool IsPersistent() = 0;
    95     // called to determine or set if a connection has been reused.
    96     virtual bool IsReused() = 0;
    97     virtual void DontReuse() = 0;
    99     // called by a transaction when the transaction reads more from the socket
   100     // than it should have (eg. containing part of the next pipelined response).
   101     virtual nsresult PushBack(const char *data, uint32_t length) = 0;
   103     // Used to determine if the connection wants read events even though
   104     // it has not written out a transaction. Used when a connection has issued
   105     // a preamble such as a proxy ssl CONNECT sequence.
   106     virtual bool IsProxyConnectInProgress() = 0;
   108     // Used by a transaction to manage the state of previous response bodies on
   109     // the same connection and work around buggy servers.
   110     virtual bool LastTransactionExpectedNoContent() = 0;
   111     virtual void   SetLastTransactionExpectedNoContent(bool) = 0;
   113     // Transfer the base http connection object along with a
   114     // reference to it to the caller.
   115     virtual nsHttpConnection *TakeHttpConnection() = 0;
   117     // Get the nsISocketTransport used by the connection without changing
   118     //  references or ownership.
   119     virtual nsISocketTransport *Transport() = 0;
   121     // Cancel and reschedule transactions deeper than the current response.
   122     // Returns the number of canceled transactions.
   123     virtual uint32_t CancelPipeline(nsresult originalReason) = 0;
   125     // Read and write class of transaction that is carried on this connection
   126     virtual nsAHttpTransaction::Classifier Classification() = 0;
   127     virtual void Classify(nsAHttpTransaction::Classifier newclass) = 0;
   129     // The number of transaction bytes written out on this HTTP Connection, does
   130     // not count CONNECT tunnel setup
   131     virtual int64_t BytesWritten() = 0;
   133     // Update the callbacks used to provide security info. May be called on
   134     // any thread.
   135     virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) = 0;
   136 };
   138 #define NS_DECL_NSAHTTPCONNECTION(fwdObject)                    \
   139     nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpRequestHead *, nsHttpResponseHead *, bool *reset); \
   140     void CloseTransaction(nsAHttpTransaction *, nsresult); \
   141     nsresult TakeTransport(nsISocketTransport **,    \
   142                            nsIAsyncInputStream **,   \
   143                            nsIAsyncOutputStream **); \
   144     bool IsPersistent(); \
   145     bool IsReused(); \
   146     void DontReuse();  \
   147     nsresult PushBack(const char *, uint32_t); \
   148     nsHttpConnection *TakeHttpConnection(); \
   149     uint32_t CancelPipeline(nsresult originalReason);   \
   150     nsAHttpTransaction::Classifier Classification();      \
   151     /*                                                    \
   152        Thes methods below have automatic definitions that just forward the \
   153        function to a lower level connection object        \
   154     */                                                    \
   155     void GetConnectionInfo(nsHttpConnectionInfo **result) \
   156     {                                                     \
   157       if (!(fwdObject)) {                                 \
   158           *result = nullptr;                               \
   159           return;                                         \
   160       }                                                   \
   161         return (fwdObject)->GetConnectionInfo(result);    \
   162     }                                                     \
   163     void GetSecurityInfo(nsISupports **result)            \
   164     {                                                     \
   165       if (!(fwdObject)) {                                 \
   166           *result = nullptr;                               \
   167           return;                                         \
   168       }                                                   \
   169       return (fwdObject)->GetSecurityInfo(result);        \
   170     }                                                     \
   171     nsresult ResumeSend()                  \
   172     {                                      \
   173         if (!(fwdObject))                  \
   174             return NS_ERROR_FAILURE;       \
   175         return (fwdObject)->ResumeSend();  \
   176     }                                      \
   177     nsresult ResumeRecv()                  \
   178     {                                      \
   179         if (!(fwdObject))                  \
   180             return NS_ERROR_FAILURE;       \
   181         return (fwdObject)->ResumeRecv();  \
   182     }                                      \
   183     nsresult ForceRecv()                   \
   184     {                                      \
   185         if (!(fwdObject))                  \
   186             return NS_ERROR_FAILURE;       \
   187         return (fwdObject)->ForceRecv();   \
   188     }                                      \
   189     nsISocketTransport *Transport()        \
   190     {                                      \
   191         if (!(fwdObject))                  \
   192             return nullptr;                 \
   193         return (fwdObject)->Transport();   \
   194     }                                      \
   195     bool IsProxyConnectInProgress()                         \
   196     {                                                       \
   197         return (fwdObject)->IsProxyConnectInProgress();     \
   198     }                                                       \
   199     bool LastTransactionExpectedNoContent()                 \
   200     {                                                       \
   201         return (fwdObject)->LastTransactionExpectedNoContent(); \
   202     }                                                       \
   203     void SetLastTransactionExpectedNoContent(bool val)      \
   204     {                                                       \
   205         return (fwdObject)->SetLastTransactionExpectedNoContent(val); \
   206     }                                                       \
   207     void Classify(nsAHttpTransaction::Classifier newclass)  \
   208     {                                                       \
   209     if (fwdObject)                                          \
   210         return (fwdObject)->Classify(newclass);             \
   211     }                                                       \
   212     int64_t BytesWritten()                                  \
   213     {     return fwdObject ? (fwdObject)->BytesWritten() : 0; } \
   214     void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) \
   215     {                                                       \
   216         if (fwdObject)                                      \
   217             (fwdObject)->SetSecurityCallbacks(aCallbacks);  \
   218     }
   220 }} // namespace mozilla::net
   222 #endif // nsAHttpConnection_h__

mercurial