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