netwerk/protocol/http/nsAHttpConnection.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/protocol/http/nsAHttpConnection.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,222 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsAHttpConnection_h__
     1.9 +#define nsAHttpConnection_h__
    1.10 +
    1.11 +#include "nsISupports.h"
    1.12 +#include "nsAHttpTransaction.h"
    1.13 +
    1.14 +class nsISocketTransport;
    1.15 +class nsIAsyncInputStream;
    1.16 +class nsIAsyncOutputStream;
    1.17 +
    1.18 +namespace mozilla { namespace net {
    1.19 +
    1.20 +class nsHttpConnectionInfo;
    1.21 +class nsHttpConnection;
    1.22 +
    1.23 +//-----------------------------------------------------------------------------
    1.24 +// Abstract base class for a HTTP connection
    1.25 +//-----------------------------------------------------------------------------
    1.26 +
    1.27 +class nsAHttpConnection : public nsISupports
    1.28 +{
    1.29 +public:
    1.30 +    //-------------------------------------------------------------------------
    1.31 +    // NOTE: these methods may only be called on the socket thread.
    1.32 +    //-------------------------------------------------------------------------
    1.33 +
    1.34 +    //
    1.35 +    // called by a transaction when the response headers have all been read.
    1.36 +    // the connection can force the transaction to reset it's response headers,
    1.37 +    // and prepare for a new set of response headers, by setting |*reset=TRUE|.
    1.38 +    //
    1.39 +    // @return failure code to close the transaction.
    1.40 +    //
    1.41 +    virtual nsresult OnHeadersAvailable(nsAHttpTransaction *,
    1.42 +                                        nsHttpRequestHead *,
    1.43 +                                        nsHttpResponseHead *,
    1.44 +                                        bool *reset) = 0;
    1.45 +
    1.46 +    //
    1.47 +    // called by a transaction to resume either sending or receiving data
    1.48 +    // after a transaction returned NS_BASE_STREAM_WOULD_BLOCK from its
    1.49 +    // ReadSegments/WriteSegments methods.
    1.50 +    //
    1.51 +    virtual nsresult ResumeSend() = 0;
    1.52 +    virtual nsresult ResumeRecv() = 0;
    1.53 +
    1.54 +    // called by a transaction to force a "read from network" iteration
    1.55 +    // even if not scheduled by socket associated with connection
    1.56 +    virtual nsresult ForceRecv() = 0;
    1.57 +
    1.58 +    // After a connection has had ResumeSend() called by a transaction,
    1.59 +    // and it is ready to write to the network it may need to know the
    1.60 +    // transaction that has data to write. This is only an issue for
    1.61 +    // multiplexed protocols like SPDY - plain HTTP or pipelined HTTP
    1.62 +    // implicitly have this information in a 1:1 relationship with the
    1.63 +    // transaction(s) they manage.
    1.64 +    virtual void TransactionHasDataToWrite(nsAHttpTransaction *)
    1.65 +    {
    1.66 +        // by default do nothing - only multiplexed protocols need to overload
    1.67 +        return;
    1.68 +    }
    1.69 +    //
    1.70 +    // called by the connection manager to close a transaction being processed
    1.71 +    // by this connection.
    1.72 +    //
    1.73 +    // @param transaction
    1.74 +    //        the transaction being closed.
    1.75 +    // @param reason
    1.76 +    //        the reason for closing the transaction.  NS_BASE_STREAM_CLOSED
    1.77 +    //        is equivalent to NS_OK.
    1.78 +    //
    1.79 +    virtual void CloseTransaction(nsAHttpTransaction *transaction,
    1.80 +                                  nsresult reason) = 0;
    1.81 +
    1.82 +    // get a reference to the connection's connection info object.
    1.83 +    virtual void GetConnectionInfo(nsHttpConnectionInfo **) = 0;
    1.84 +
    1.85 +    // get the transport level information for this connection. This may fail
    1.86 +    // if it is in use.
    1.87 +    virtual nsresult TakeTransport(nsISocketTransport **,
    1.88 +                                   nsIAsyncInputStream **,
    1.89 +                                   nsIAsyncOutputStream **) = 0;
    1.90 +
    1.91 +    // called by a transaction to get the security info from the socket.
    1.92 +    virtual void GetSecurityInfo(nsISupports **) = 0;
    1.93 +
    1.94 +    // called by a transaction to determine whether or not the connection is
    1.95 +    // persistent... important in determining the end of a response.
    1.96 +    virtual bool IsPersistent() = 0;
    1.97 +
    1.98 +    // called to determine or set if a connection has been reused.
    1.99 +    virtual bool IsReused() = 0;
   1.100 +    virtual void DontReuse() = 0;
   1.101 +
   1.102 +    // called by a transaction when the transaction reads more from the socket
   1.103 +    // than it should have (eg. containing part of the next pipelined response).
   1.104 +    virtual nsresult PushBack(const char *data, uint32_t length) = 0;
   1.105 +
   1.106 +    // Used to determine if the connection wants read events even though
   1.107 +    // it has not written out a transaction. Used when a connection has issued
   1.108 +    // a preamble such as a proxy ssl CONNECT sequence.
   1.109 +    virtual bool IsProxyConnectInProgress() = 0;
   1.110 +
   1.111 +    // Used by a transaction to manage the state of previous response bodies on
   1.112 +    // the same connection and work around buggy servers.
   1.113 +    virtual bool LastTransactionExpectedNoContent() = 0;
   1.114 +    virtual void   SetLastTransactionExpectedNoContent(bool) = 0;
   1.115 +
   1.116 +    // Transfer the base http connection object along with a
   1.117 +    // reference to it to the caller.
   1.118 +    virtual nsHttpConnection *TakeHttpConnection() = 0;
   1.119 +
   1.120 +    // Get the nsISocketTransport used by the connection without changing
   1.121 +    //  references or ownership.
   1.122 +    virtual nsISocketTransport *Transport() = 0;
   1.123 +
   1.124 +    // Cancel and reschedule transactions deeper than the current response.
   1.125 +    // Returns the number of canceled transactions.
   1.126 +    virtual uint32_t CancelPipeline(nsresult originalReason) = 0;
   1.127 +
   1.128 +    // Read and write class of transaction that is carried on this connection
   1.129 +    virtual nsAHttpTransaction::Classifier Classification() = 0;
   1.130 +    virtual void Classify(nsAHttpTransaction::Classifier newclass) = 0;
   1.131 +
   1.132 +    // The number of transaction bytes written out on this HTTP Connection, does
   1.133 +    // not count CONNECT tunnel setup
   1.134 +    virtual int64_t BytesWritten() = 0;
   1.135 +
   1.136 +    // Update the callbacks used to provide security info. May be called on
   1.137 +    // any thread.
   1.138 +    virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) = 0;
   1.139 +};
   1.140 +
   1.141 +#define NS_DECL_NSAHTTPCONNECTION(fwdObject)                    \
   1.142 +    nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpRequestHead *, nsHttpResponseHead *, bool *reset); \
   1.143 +    void CloseTransaction(nsAHttpTransaction *, nsresult); \
   1.144 +    nsresult TakeTransport(nsISocketTransport **,    \
   1.145 +                           nsIAsyncInputStream **,   \
   1.146 +                           nsIAsyncOutputStream **); \
   1.147 +    bool IsPersistent(); \
   1.148 +    bool IsReused(); \
   1.149 +    void DontReuse();  \
   1.150 +    nsresult PushBack(const char *, uint32_t); \
   1.151 +    nsHttpConnection *TakeHttpConnection(); \
   1.152 +    uint32_t CancelPipeline(nsresult originalReason);   \
   1.153 +    nsAHttpTransaction::Classifier Classification();      \
   1.154 +    /*                                                    \
   1.155 +       Thes methods below have automatic definitions that just forward the \
   1.156 +       function to a lower level connection object        \
   1.157 +    */                                                    \
   1.158 +    void GetConnectionInfo(nsHttpConnectionInfo **result) \
   1.159 +    {                                                     \
   1.160 +      if (!(fwdObject)) {                                 \
   1.161 +          *result = nullptr;                               \
   1.162 +          return;                                         \
   1.163 +      }                                                   \
   1.164 +        return (fwdObject)->GetConnectionInfo(result);    \
   1.165 +    }                                                     \
   1.166 +    void GetSecurityInfo(nsISupports **result)            \
   1.167 +    {                                                     \
   1.168 +      if (!(fwdObject)) {                                 \
   1.169 +          *result = nullptr;                               \
   1.170 +          return;                                         \
   1.171 +      }                                                   \
   1.172 +      return (fwdObject)->GetSecurityInfo(result);        \
   1.173 +    }                                                     \
   1.174 +    nsresult ResumeSend()                  \
   1.175 +    {                                      \
   1.176 +        if (!(fwdObject))                  \
   1.177 +            return NS_ERROR_FAILURE;       \
   1.178 +        return (fwdObject)->ResumeSend();  \
   1.179 +    }                                      \
   1.180 +    nsresult ResumeRecv()                  \
   1.181 +    {                                      \
   1.182 +        if (!(fwdObject))                  \
   1.183 +            return NS_ERROR_FAILURE;       \
   1.184 +        return (fwdObject)->ResumeRecv();  \
   1.185 +    }                                      \
   1.186 +    nsresult ForceRecv()                   \
   1.187 +    {                                      \
   1.188 +        if (!(fwdObject))                  \
   1.189 +            return NS_ERROR_FAILURE;       \
   1.190 +        return (fwdObject)->ForceRecv();   \
   1.191 +    }                                      \
   1.192 +    nsISocketTransport *Transport()        \
   1.193 +    {                                      \
   1.194 +        if (!(fwdObject))                  \
   1.195 +            return nullptr;                 \
   1.196 +        return (fwdObject)->Transport();   \
   1.197 +    }                                      \
   1.198 +    bool IsProxyConnectInProgress()                         \
   1.199 +    {                                                       \
   1.200 +        return (fwdObject)->IsProxyConnectInProgress();     \
   1.201 +    }                                                       \
   1.202 +    bool LastTransactionExpectedNoContent()                 \
   1.203 +    {                                                       \
   1.204 +        return (fwdObject)->LastTransactionExpectedNoContent(); \
   1.205 +    }                                                       \
   1.206 +    void SetLastTransactionExpectedNoContent(bool val)      \
   1.207 +    {                                                       \
   1.208 +        return (fwdObject)->SetLastTransactionExpectedNoContent(val); \
   1.209 +    }                                                       \
   1.210 +    void Classify(nsAHttpTransaction::Classifier newclass)  \
   1.211 +    {                                                       \
   1.212 +    if (fwdObject)                                          \
   1.213 +        return (fwdObject)->Classify(newclass);             \
   1.214 +    }                                                       \
   1.215 +    int64_t BytesWritten()                                  \
   1.216 +    {     return fwdObject ? (fwdObject)->BytesWritten() : 0; } \
   1.217 +    void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) \
   1.218 +    {                                                       \
   1.219 +        if (fwdObject)                                      \
   1.220 +            (fwdObject)->SetSecurityCallbacks(aCallbacks);  \
   1.221 +    }
   1.222 +
   1.223 +}} // namespace mozilla::net
   1.224 +
   1.225 +#endif // nsAHttpConnection_h__

mercurial