netwerk/protocol/http/nsAHttpTransaction.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsAHttpTransaction_h__
michael@0 6 #define nsAHttpTransaction_h__
michael@0 7
michael@0 8 #include "nsISupports.h"
michael@0 9 #include "nsTArray.h"
michael@0 10
michael@0 11 class nsIInterfaceRequestor;
michael@0 12 class nsIEventTarget;
michael@0 13 class nsITransport;
michael@0 14 class nsILoadGroupConnectionInfo;
michael@0 15
michael@0 16 namespace mozilla { namespace net {
michael@0 17
michael@0 18 class nsAHttpConnection;
michael@0 19 class nsAHttpSegmentReader;
michael@0 20 class nsAHttpSegmentWriter;
michael@0 21 class nsHttpTransaction;
michael@0 22 class nsHttpPipeline;
michael@0 23 class nsHttpRequestHead;
michael@0 24
michael@0 25 //----------------------------------------------------------------------------
michael@0 26 // Abstract base class for a HTTP transaction:
michael@0 27 //
michael@0 28 // A transaction is a "sink" for the response data. The connection pushes
michael@0 29 // data to the transaction by writing to it. The transaction supports
michael@0 30 // WriteSegments and may refuse to accept data if its buffers are full (its
michael@0 31 // write function returns NS_BASE_STREAM_WOULD_BLOCK in this case).
michael@0 32 //----------------------------------------------------------------------------
michael@0 33
michael@0 34 class nsAHttpTransaction : public nsISupports
michael@0 35 {
michael@0 36 public:
michael@0 37 // called by the connection when it takes ownership of the transaction.
michael@0 38 virtual void SetConnection(nsAHttpConnection *) = 0;
michael@0 39
michael@0 40 // used to obtain the connection associated with this transaction
michael@0 41 virtual nsAHttpConnection *Connection() = 0;
michael@0 42
michael@0 43 // called by the connection to get security callbacks to set on the
michael@0 44 // socket transport.
michael@0 45 virtual void GetSecurityCallbacks(nsIInterfaceRequestor **) = 0;
michael@0 46
michael@0 47 // called to report socket status (see nsITransportEventSink)
michael@0 48 virtual void OnTransportStatus(nsITransport* transport,
michael@0 49 nsresult status, uint64_t progress) = 0;
michael@0 50
michael@0 51 // called to check the transaction status.
michael@0 52 virtual bool IsDone() = 0;
michael@0 53 virtual nsresult Status() = 0;
michael@0 54 virtual uint32_t Caps() = 0;
michael@0 55
michael@0 56 // called to notify that a requested DNS cache entry was refreshed.
michael@0 57 virtual void SetDNSWasRefreshed() = 0;
michael@0 58
michael@0 59 // called to find out how much request data is available for writing.
michael@0 60 virtual uint64_t Available() = 0;
michael@0 61
michael@0 62 // called to read request data from the transaction.
michael@0 63 virtual nsresult ReadSegments(nsAHttpSegmentReader *reader,
michael@0 64 uint32_t count, uint32_t *countRead) = 0;
michael@0 65
michael@0 66 // called to write response data to the transaction.
michael@0 67 virtual nsresult WriteSegments(nsAHttpSegmentWriter *writer,
michael@0 68 uint32_t count, uint32_t *countWritten) = 0;
michael@0 69
michael@0 70 // called to close the transaction
michael@0 71 virtual void Close(nsresult reason) = 0;
michael@0 72
michael@0 73 // called to indicate a failure with proxy CONNECT
michael@0 74 virtual void SetProxyConnectFailed() = 0;
michael@0 75
michael@0 76 // called to retrieve the request headers of the transaction
michael@0 77 virtual nsHttpRequestHead *RequestHead() = 0;
michael@0 78
michael@0 79 // determine the number of real http/1.x transactions on this
michael@0 80 // abstract object. Pipelines may have multiple, SPDY has 0,
michael@0 81 // normal http transactions have 1.
michael@0 82 virtual uint32_t Http1xTransactionCount() = 0;
michael@0 83
michael@0 84 // called to remove the unused sub transactions from an object that can
michael@0 85 // handle multiple transactions simultaneously (i.e. pipelines or spdy).
michael@0 86 //
michael@0 87 // Returns NS_ERROR_NOT_IMPLEMENTED if the object does not implement
michael@0 88 // sub-transactions.
michael@0 89 //
michael@0 90 // Returns NS_ERROR_ALREADY_OPENED if the subtransactions have been
michael@0 91 // at least partially written and cannot be moved.
michael@0 92 //
michael@0 93 virtual nsresult TakeSubTransactions(
michael@0 94 nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions) = 0;
michael@0 95
michael@0 96 // called to add a sub-transaction in the case of pipelined transactions
michael@0 97 // classes that do not implement sub transactions
michael@0 98 // return NS_ERROR_NOT_IMPLEMENTED
michael@0 99 virtual nsresult AddTransaction(nsAHttpTransaction *transaction) = 0;
michael@0 100
michael@0 101 // The total length of the outstanding pipeline comprised of transacations
michael@0 102 // and sub-transactions.
michael@0 103 virtual uint32_t PipelineDepth() = 0;
michael@0 104
michael@0 105 // Used to inform the connection that it is being used in a pipelined
michael@0 106 // context. That may influence the handling of some errors.
michael@0 107 // The value is the pipeline position (> 1).
michael@0 108 virtual nsresult SetPipelinePosition(int32_t) = 0;
michael@0 109 virtual int32_t PipelinePosition() = 0;
michael@0 110
michael@0 111 // Occasionally the abstract interface has to give way to base implementations
michael@0 112 // to respect differences between spdy, pipelines, etc..
michael@0 113 // These Query* (and IsNUllTransaction()) functions provide a way to do
michael@0 114 // that without using xpcom or rtti. Any calling code that can't deal with
michael@0 115 // a null response from one of them probably shouldn't be using nsAHttpTransaction
michael@0 116
michael@0 117 // If we used rtti this would be the result of doing
michael@0 118 // dynamic_cast<nsHttpPipeline *>(this).. i.e. it can be nullptr for
michael@0 119 // non pipeline implementations of nsAHttpTransaction
michael@0 120 virtual nsHttpPipeline *QueryPipeline() { return nullptr; }
michael@0 121
michael@0 122 // equivalent to !!dynamic_cast<NullHttpTransaction *>(this)
michael@0 123 // A null transaction is expected to return BASE_STREAM_CLOSED on all of
michael@0 124 // its IO functions all the time.
michael@0 125 virtual bool IsNullTransaction() { return false; }
michael@0 126
michael@0 127 // return the load group connection information associated with the transaction
michael@0 128 virtual nsILoadGroupConnectionInfo *LoadGroupConnectionInfo() { return nullptr; }
michael@0 129
michael@0 130 // The base definition of these is done in nsHttpTransaction.cpp
michael@0 131 virtual bool ResponseTimeoutEnabled() const;
michael@0 132 virtual PRIntervalTime ResponseTimeout();
michael@0 133
michael@0 134 // Every transaction is classified into one of the types below. When using
michael@0 135 // HTTP pipelines, only transactions with the same type appear on the same
michael@0 136 // pipeline.
michael@0 137 enum Classifier {
michael@0 138 // Transactions that expect a short 304 (no-content) response
michael@0 139 CLASS_REVALIDATION,
michael@0 140
michael@0 141 // Transactions for content expected to be CSS or JS
michael@0 142 CLASS_SCRIPT,
michael@0 143
michael@0 144 // Transactions for content expected to be an image
michael@0 145 CLASS_IMAGE,
michael@0 146
michael@0 147 // Transactions that cannot involve a pipeline
michael@0 148 CLASS_SOLO,
michael@0 149
michael@0 150 // Transactions that do not fit any of the other categories. HTML
michael@0 151 // is normally GENERAL.
michael@0 152 CLASS_GENERAL,
michael@0 153
michael@0 154 CLASS_MAX
michael@0 155 };
michael@0 156 };
michael@0 157
michael@0 158 #define NS_DECL_NSAHTTPTRANSACTION \
michael@0 159 void SetConnection(nsAHttpConnection *); \
michael@0 160 nsAHttpConnection *Connection(); \
michael@0 161 void GetSecurityCallbacks(nsIInterfaceRequestor **); \
michael@0 162 void OnTransportStatus(nsITransport* transport, \
michael@0 163 nsresult status, uint64_t progress); \
michael@0 164 bool IsDone(); \
michael@0 165 nsresult Status(); \
michael@0 166 uint32_t Caps(); \
michael@0 167 void SetDNSWasRefreshed(); \
michael@0 168 uint64_t Available(); \
michael@0 169 nsresult ReadSegments(nsAHttpSegmentReader *, uint32_t, uint32_t *); \
michael@0 170 nsresult WriteSegments(nsAHttpSegmentWriter *, uint32_t, uint32_t *); \
michael@0 171 void Close(nsresult reason); \
michael@0 172 void SetProxyConnectFailed(); \
michael@0 173 nsHttpRequestHead *RequestHead(); \
michael@0 174 uint32_t Http1xTransactionCount(); \
michael@0 175 nsresult TakeSubTransactions(nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions); \
michael@0 176 nsresult AddTransaction(nsAHttpTransaction *); \
michael@0 177 uint32_t PipelineDepth(); \
michael@0 178 nsresult SetPipelinePosition(int32_t); \
michael@0 179 int32_t PipelinePosition();
michael@0 180
michael@0 181 //-----------------------------------------------------------------------------
michael@0 182 // nsAHttpSegmentReader
michael@0 183 //-----------------------------------------------------------------------------
michael@0 184
michael@0 185 class nsAHttpSegmentReader
michael@0 186 {
michael@0 187 public:
michael@0 188 // any returned failure code stops segment iteration
michael@0 189 virtual nsresult OnReadSegment(const char *segment,
michael@0 190 uint32_t count,
michael@0 191 uint32_t *countRead) = 0;
michael@0 192
michael@0 193 // Ask the segment reader to commit to accepting size bytes of
michael@0 194 // data from subsequent OnReadSegment() calls or throw hard
michael@0 195 // (i.e. not wouldblock) exceptions. Implementations
michael@0 196 // can return NS_ERROR_FAILURE if they never make commitments of that size
michael@0 197 // (the default), NS_OK if they make the commitment, or
michael@0 198 // NS_BASE_STREAM_WOULD_BLOCK if they cannot make the
michael@0 199 // commitment now but might in the future and forceCommitment is not true .
michael@0 200 // (forceCommitment requires a hard failure or OK at this moment.)
michael@0 201 //
michael@0 202 // SpdySession uses this to make sure frames are atomic.
michael@0 203 virtual nsresult CommitToSegmentSize(uint32_t size, bool forceCommitment)
michael@0 204 {
michael@0 205 return NS_ERROR_FAILURE;
michael@0 206 }
michael@0 207 };
michael@0 208
michael@0 209 #define NS_DECL_NSAHTTPSEGMENTREADER \
michael@0 210 nsresult OnReadSegment(const char *, uint32_t, uint32_t *);
michael@0 211
michael@0 212 //-----------------------------------------------------------------------------
michael@0 213 // nsAHttpSegmentWriter
michael@0 214 //-----------------------------------------------------------------------------
michael@0 215
michael@0 216 class nsAHttpSegmentWriter
michael@0 217 {
michael@0 218 public:
michael@0 219 // any returned failure code stops segment iteration
michael@0 220 virtual nsresult OnWriteSegment(char *segment,
michael@0 221 uint32_t count,
michael@0 222 uint32_t *countWritten) = 0;
michael@0 223 };
michael@0 224
michael@0 225 #define NS_DECL_NSAHTTPSEGMENTWRITER \
michael@0 226 nsresult OnWriteSegment(char *, uint32_t, uint32_t *);
michael@0 227
michael@0 228 }} // namespace mozilla::net
michael@0 229
michael@0 230 #endif // nsAHttpTransaction_h__

mercurial