netwerk/protocol/http/nsAHttpTransaction.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/protocol/http/nsAHttpTransaction.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,230 @@
     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 nsAHttpTransaction_h__
     1.9 +#define nsAHttpTransaction_h__
    1.10 +
    1.11 +#include "nsISupports.h"
    1.12 +#include "nsTArray.h"
    1.13 +
    1.14 +class nsIInterfaceRequestor;
    1.15 +class nsIEventTarget;
    1.16 +class nsITransport;
    1.17 +class nsILoadGroupConnectionInfo;
    1.18 +
    1.19 +namespace mozilla { namespace net {
    1.20 +
    1.21 +class nsAHttpConnection;
    1.22 +class nsAHttpSegmentReader;
    1.23 +class nsAHttpSegmentWriter;
    1.24 +class nsHttpTransaction;
    1.25 +class nsHttpPipeline;
    1.26 +class nsHttpRequestHead;
    1.27 +
    1.28 +//----------------------------------------------------------------------------
    1.29 +// Abstract base class for a HTTP transaction:
    1.30 +//
    1.31 +// A transaction is a "sink" for the response data.  The connection pushes
    1.32 +// data to the transaction by writing to it.  The transaction supports
    1.33 +// WriteSegments and may refuse to accept data if its buffers are full (its
    1.34 +// write function returns NS_BASE_STREAM_WOULD_BLOCK in this case).
    1.35 +//----------------------------------------------------------------------------
    1.36 +
    1.37 +class nsAHttpTransaction : public nsISupports
    1.38 +{
    1.39 +public:
    1.40 +    // called by the connection when it takes ownership of the transaction.
    1.41 +    virtual void SetConnection(nsAHttpConnection *) = 0;
    1.42 +
    1.43 +    // used to obtain the connection associated with this transaction
    1.44 +    virtual nsAHttpConnection *Connection() = 0;
    1.45 +
    1.46 +    // called by the connection to get security callbacks to set on the
    1.47 +    // socket transport.
    1.48 +    virtual void GetSecurityCallbacks(nsIInterfaceRequestor **) = 0;
    1.49 +
    1.50 +    // called to report socket status (see nsITransportEventSink)
    1.51 +    virtual void OnTransportStatus(nsITransport* transport,
    1.52 +                                   nsresult status, uint64_t progress) = 0;
    1.53 +
    1.54 +    // called to check the transaction status.
    1.55 +    virtual bool     IsDone() = 0;
    1.56 +    virtual nsresult Status() = 0;
    1.57 +    virtual uint32_t Caps() = 0;
    1.58 +
    1.59 +    // called to notify that a requested DNS cache entry was refreshed.
    1.60 +    virtual void     SetDNSWasRefreshed() = 0;
    1.61 +
    1.62 +    // called to find out how much request data is available for writing.
    1.63 +    virtual uint64_t Available() = 0;
    1.64 +
    1.65 +    // called to read request data from the transaction.
    1.66 +    virtual nsresult ReadSegments(nsAHttpSegmentReader *reader,
    1.67 +                                  uint32_t count, uint32_t *countRead) = 0;
    1.68 +
    1.69 +    // called to write response data to the transaction.
    1.70 +    virtual nsresult WriteSegments(nsAHttpSegmentWriter *writer,
    1.71 +                                   uint32_t count, uint32_t *countWritten) = 0;
    1.72 +
    1.73 +    // called to close the transaction
    1.74 +    virtual void Close(nsresult reason) = 0;
    1.75 +
    1.76 +    // called to indicate a failure with proxy CONNECT
    1.77 +    virtual void SetProxyConnectFailed() = 0;
    1.78 +
    1.79 +    // called to retrieve the request headers of the transaction
    1.80 +    virtual nsHttpRequestHead *RequestHead() = 0;
    1.81 +
    1.82 +    // determine the number of real http/1.x transactions on this
    1.83 +    // abstract object. Pipelines may have multiple, SPDY has 0,
    1.84 +    // normal http transactions have 1.
    1.85 +    virtual uint32_t Http1xTransactionCount() = 0;
    1.86 +
    1.87 +    // called to remove the unused sub transactions from an object that can
    1.88 +    // handle multiple transactions simultaneously (i.e. pipelines or spdy).
    1.89 +    //
    1.90 +    // Returns NS_ERROR_NOT_IMPLEMENTED if the object does not implement
    1.91 +    // sub-transactions.
    1.92 +    //
    1.93 +    // Returns NS_ERROR_ALREADY_OPENED if the subtransactions have been
    1.94 +    // at least partially written and cannot be moved.
    1.95 +    //
    1.96 +    virtual nsresult TakeSubTransactions(
    1.97 +        nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions) = 0;
    1.98 +
    1.99 +    // called to add a sub-transaction in the case of pipelined transactions
   1.100 +    // classes that do not implement sub transactions
   1.101 +    // return NS_ERROR_NOT_IMPLEMENTED
   1.102 +    virtual nsresult AddTransaction(nsAHttpTransaction *transaction) = 0;
   1.103 +
   1.104 +    // The total length of the outstanding pipeline comprised of transacations
   1.105 +    // and sub-transactions.
   1.106 +    virtual uint32_t PipelineDepth() = 0;
   1.107 +
   1.108 +    // Used to inform the connection that it is being used in a pipelined
   1.109 +    // context. That may influence the handling of some errors.
   1.110 +    // The value is the pipeline position (> 1).
   1.111 +    virtual nsresult SetPipelinePosition(int32_t) = 0;
   1.112 +    virtual int32_t  PipelinePosition() = 0;
   1.113 +
   1.114 +    // Occasionally the abstract interface has to give way to base implementations
   1.115 +    // to respect differences between spdy, pipelines, etc..
   1.116 +    // These Query* (and IsNUllTransaction()) functions provide a way to do
   1.117 +    // that without using xpcom or rtti. Any calling code that can't deal with
   1.118 +    // a null response from one of them probably shouldn't be using nsAHttpTransaction
   1.119 +
   1.120 +    // If we used rtti this would be the result of doing
   1.121 +    // dynamic_cast<nsHttpPipeline *>(this).. i.e. it can be nullptr for
   1.122 +    // non pipeline implementations of nsAHttpTransaction
   1.123 +    virtual nsHttpPipeline *QueryPipeline() { return nullptr; }
   1.124 +
   1.125 +    // equivalent to !!dynamic_cast<NullHttpTransaction *>(this)
   1.126 +    // A null transaction is expected to return BASE_STREAM_CLOSED on all of
   1.127 +    // its IO functions all the time.
   1.128 +    virtual bool IsNullTransaction() { return false; }
   1.129 +
   1.130 +    // return the load group connection information associated with the transaction
   1.131 +    virtual nsILoadGroupConnectionInfo *LoadGroupConnectionInfo() { return nullptr; }
   1.132 +
   1.133 +    // The base definition of these is done in nsHttpTransaction.cpp
   1.134 +    virtual bool ResponseTimeoutEnabled() const;
   1.135 +    virtual PRIntervalTime ResponseTimeout();
   1.136 +
   1.137 +    // Every transaction is classified into one of the types below. When using
   1.138 +    // HTTP pipelines, only transactions with the same type appear on the same
   1.139 +    // pipeline.
   1.140 +    enum Classifier  {
   1.141 +        // Transactions that expect a short 304 (no-content) response
   1.142 +        CLASS_REVALIDATION,
   1.143 +
   1.144 +        // Transactions for content expected to be CSS or JS
   1.145 +        CLASS_SCRIPT,
   1.146 +
   1.147 +        // Transactions for content expected to be an image
   1.148 +        CLASS_IMAGE,
   1.149 +
   1.150 +        // Transactions that cannot involve a pipeline
   1.151 +        CLASS_SOLO,
   1.152 +
   1.153 +        // Transactions that do not fit any of the other categories. HTML
   1.154 +        // is normally GENERAL.
   1.155 +        CLASS_GENERAL,
   1.156 +
   1.157 +        CLASS_MAX
   1.158 +    };
   1.159 +};
   1.160 +
   1.161 +#define NS_DECL_NSAHTTPTRANSACTION \
   1.162 +    void SetConnection(nsAHttpConnection *); \
   1.163 +    nsAHttpConnection *Connection(); \
   1.164 +    void GetSecurityCallbacks(nsIInterfaceRequestor **);       \
   1.165 +    void OnTransportStatus(nsITransport* transport, \
   1.166 +                           nsresult status, uint64_t progress); \
   1.167 +    bool     IsDone(); \
   1.168 +    nsresult Status(); \
   1.169 +    uint32_t Caps();   \
   1.170 +    void     SetDNSWasRefreshed(); \
   1.171 +    uint64_t Available(); \
   1.172 +    nsresult ReadSegments(nsAHttpSegmentReader *, uint32_t, uint32_t *); \
   1.173 +    nsresult WriteSegments(nsAHttpSegmentWriter *, uint32_t, uint32_t *); \
   1.174 +    void     Close(nsresult reason);                                    \
   1.175 +    void     SetProxyConnectFailed();                                   \
   1.176 +    nsHttpRequestHead *RequestHead();                                   \
   1.177 +    uint32_t Http1xTransactionCount();                                  \
   1.178 +    nsresult TakeSubTransactions(nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions); \
   1.179 +    nsresult AddTransaction(nsAHttpTransaction *);                      \
   1.180 +    uint32_t PipelineDepth();                                           \
   1.181 +    nsresult SetPipelinePosition(int32_t);                              \
   1.182 +    int32_t  PipelinePosition();
   1.183 +
   1.184 +//-----------------------------------------------------------------------------
   1.185 +// nsAHttpSegmentReader
   1.186 +//-----------------------------------------------------------------------------
   1.187 +
   1.188 +class nsAHttpSegmentReader
   1.189 +{
   1.190 +public:
   1.191 +    // any returned failure code stops segment iteration
   1.192 +    virtual nsresult OnReadSegment(const char *segment,
   1.193 +                                   uint32_t count,
   1.194 +                                   uint32_t *countRead) = 0;
   1.195 +
   1.196 +    // Ask the segment reader to commit to accepting size bytes of
   1.197 +    // data from subsequent OnReadSegment() calls or throw hard
   1.198 +    // (i.e. not wouldblock) exceptions. Implementations
   1.199 +    // can return NS_ERROR_FAILURE if they never make commitments of that size
   1.200 +    // (the default), NS_OK if they make the commitment, or
   1.201 +    // NS_BASE_STREAM_WOULD_BLOCK if they cannot make the
   1.202 +    // commitment now but might in the future and forceCommitment is not true .
   1.203 +    // (forceCommitment requires a hard failure or OK at this moment.)
   1.204 +    //
   1.205 +    // SpdySession uses this to make sure frames are atomic.
   1.206 +    virtual nsresult CommitToSegmentSize(uint32_t size, bool forceCommitment)
   1.207 +    {
   1.208 +        return NS_ERROR_FAILURE;
   1.209 +    }
   1.210 +};
   1.211 +
   1.212 +#define NS_DECL_NSAHTTPSEGMENTREADER \
   1.213 +    nsresult OnReadSegment(const char *, uint32_t, uint32_t *);
   1.214 +
   1.215 +//-----------------------------------------------------------------------------
   1.216 +// nsAHttpSegmentWriter
   1.217 +//-----------------------------------------------------------------------------
   1.218 +
   1.219 +class nsAHttpSegmentWriter
   1.220 +{
   1.221 +public:
   1.222 +    // any returned failure code stops segment iteration
   1.223 +    virtual nsresult OnWriteSegment(char *segment,
   1.224 +                                    uint32_t count,
   1.225 +                                    uint32_t *countWritten) = 0;
   1.226 +};
   1.227 +
   1.228 +#define NS_DECL_NSAHTTPSEGMENTWRITER \
   1.229 +    nsresult OnWriteSegment(char *, uint32_t, uint32_t *);
   1.230 +
   1.231 +}} // namespace mozilla::net
   1.232 +
   1.233 +#endif // nsAHttpTransaction_h__

mercurial