/src/mozilla-central/netwerk/protocol/http/nsAHttpConnection.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
4 | | |
5 | | #ifndef nsAHttpConnection_h__ |
6 | | #define nsAHttpConnection_h__ |
7 | | |
8 | | #include "nsISupports.h" |
9 | | #include "nsAHttpTransaction.h" |
10 | | |
11 | | class nsISocketTransport; |
12 | | class nsIAsyncInputStream; |
13 | | class nsIAsyncOutputStream; |
14 | | |
15 | | namespace mozilla { namespace net { |
16 | | |
17 | | class nsHttpConnectionInfo; |
18 | | class nsHttpConnection; |
19 | | |
20 | | //----------------------------------------------------------------------------- |
21 | | // Abstract base class for a HTTP connection |
22 | | //----------------------------------------------------------------------------- |
23 | | |
24 | | // 5a66aed7-eede-468b-ac2b-e5fb431fcc5c |
25 | | #define NS_AHTTPCONNECTION_IID \ |
26 | | { 0x5a66aed7, 0xeede, 0x468b, {0xac, 0x2b, 0xe5, 0xfb, 0x43, 0x1f, 0xcc, 0x5c }} |
27 | | |
28 | | class nsAHttpConnection : public nsISupports |
29 | | { |
30 | | public: |
31 | | NS_DECLARE_STATIC_IID_ACCESSOR(NS_AHTTPCONNECTION_IID) |
32 | | |
33 | | //------------------------------------------------------------------------- |
34 | | // NOTE: these methods may only be called on the socket thread. |
35 | | //------------------------------------------------------------------------- |
36 | | |
37 | | // |
38 | | // called by a transaction when the response headers have all been read. |
39 | | // the connection can force the transaction to reset it's response headers, |
40 | | // and prepare for a new set of response headers, by setting |*reset=TRUE|. |
41 | | // |
42 | | // @return failure code to close the transaction. |
43 | | // |
44 | | virtual MOZ_MUST_USE nsresult OnHeadersAvailable(nsAHttpTransaction *, |
45 | | nsHttpRequestHead *, |
46 | | nsHttpResponseHead *, |
47 | | bool *reset) = 0; |
48 | | |
49 | | // |
50 | | // called by a transaction to resume either sending or receiving data |
51 | | // after a transaction returned NS_BASE_STREAM_WOULD_BLOCK from its |
52 | | // ReadSegments/WriteSegments methods. |
53 | | // |
54 | | virtual MOZ_MUST_USE nsresult ResumeSend() = 0; |
55 | | virtual MOZ_MUST_USE nsresult ResumeRecv() = 0; |
56 | | |
57 | | // called by a transaction to force a "send/recv from network" iteration |
58 | | // even if not scheduled by socket associated with connection |
59 | | virtual MOZ_MUST_USE nsresult ForceSend() = 0; |
60 | | virtual MOZ_MUST_USE nsresult ForceRecv() = 0; |
61 | | |
62 | | // After a connection has had ResumeSend() called by a transaction, |
63 | | // and it is ready to write to the network it may need to know the |
64 | | // transaction that has data to write. This is only an issue for |
65 | | // multiplexed protocols like SPDY - h1 |
66 | | // implicitly has this information in a 1:1 relationship with the |
67 | | // transaction(s) they manage. |
68 | | virtual void TransactionHasDataToWrite(nsAHttpTransaction *) |
69 | 0 | { |
70 | 0 | // by default do nothing - only multiplexed protocols need to overload |
71 | 0 | } |
72 | | |
73 | | // This is the companion to *HasDataToWrite() for the case |
74 | | // when a gecko caller has called ResumeRecv() after being paused |
75 | | virtual void TransactionHasDataToRecv(nsAHttpTransaction *) |
76 | 0 | { |
77 | 0 | // by default do nothing - only multiplexed protocols need to overload |
78 | 0 | } |
79 | | |
80 | | // called by the connection manager to close a transaction being processed |
81 | | // by this connection. |
82 | | // |
83 | | // @param transaction |
84 | | // the transaction being closed. |
85 | | // @param reason |
86 | | // the reason for closing the transaction. NS_BASE_STREAM_CLOSED |
87 | | // is equivalent to NS_OK. |
88 | | // |
89 | | virtual void CloseTransaction(nsAHttpTransaction *transaction, |
90 | | nsresult reason) = 0; |
91 | | |
92 | | // get a reference to the connection's connection info object. |
93 | | virtual void GetConnectionInfo(nsHttpConnectionInfo **) = 0; |
94 | | |
95 | | // get the transport level information for this connection. This may fail |
96 | | // if it is in use. |
97 | | virtual MOZ_MUST_USE nsresult TakeTransport(nsISocketTransport **, |
98 | | nsIAsyncInputStream **, |
99 | | nsIAsyncOutputStream **) = 0; |
100 | | |
101 | | // called by a transaction to get the security info from the socket. |
102 | | virtual void GetSecurityInfo(nsISupports **) = 0; |
103 | | |
104 | | // called by a transaction to determine whether or not the connection is |
105 | | // persistent... important in determining the end of a response. |
106 | | virtual bool IsPersistent() = 0; |
107 | | |
108 | | // called to determine or set if a connection has been reused. |
109 | | virtual bool IsReused() = 0; |
110 | | virtual void DontReuse() = 0; |
111 | | |
112 | | // called by a transaction when the transaction reads more from the socket |
113 | | // than it should have (eg. containing part of the next response). |
114 | | virtual MOZ_MUST_USE nsresult PushBack(const char *data, uint32_t length) = 0; |
115 | | |
116 | | // Used to determine if the connection wants read events even though |
117 | | // it has not written out a transaction. Used when a connection has issued |
118 | | // a preamble such as a proxy ssl CONNECT sequence. |
119 | | virtual bool IsProxyConnectInProgress() = 0; |
120 | | |
121 | | // Used by a transaction to manage the state of previous response bodies on |
122 | | // the same connection and work around buggy servers. |
123 | | virtual bool LastTransactionExpectedNoContent() = 0; |
124 | | virtual void SetLastTransactionExpectedNoContent(bool) = 0; |
125 | | |
126 | | // Transfer the base http connection object along with a |
127 | | // reference to it to the caller. |
128 | | virtual already_AddRefed<nsHttpConnection> TakeHttpConnection() = 0; |
129 | | |
130 | | // Like TakeHttpConnection() but do not drop our own ref |
131 | | virtual already_AddRefed<nsHttpConnection> HttpConnection() = 0; |
132 | | |
133 | | // Get the nsISocketTransport used by the connection without changing |
134 | | // references or ownership. |
135 | | virtual nsISocketTransport *Transport() = 0; |
136 | | |
137 | | // The number of transaction bytes written out on this HTTP Connection, does |
138 | | // not count CONNECT tunnel setup |
139 | | virtual int64_t BytesWritten() = 0; |
140 | | |
141 | | // Update the callbacks used to provide security info. May be called on |
142 | | // any thread. |
143 | | virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) = 0; |
144 | | |
145 | | // nsHttp.h version |
146 | | virtual HttpVersion Version() = 0; |
147 | | |
148 | | // A notification of the current active tab id change. |
149 | | virtual void TopLevelOuterContentWindowIdChanged(uint64_t windowId) = 0; |
150 | | }; |
151 | | |
152 | | NS_DEFINE_STATIC_IID_ACCESSOR(nsAHttpConnection, NS_AHTTPCONNECTION_IID) |
153 | | |
154 | | #define NS_DECL_NSAHTTPCONNECTION(fwdObject) \ |
155 | | MOZ_MUST_USE nsresult OnHeadersAvailable(nsAHttpTransaction *, \ |
156 | | nsHttpRequestHead *, \ |
157 | | nsHttpResponseHead *, \ |
158 | | bool *reset) override; \ |
159 | | void CloseTransaction(nsAHttpTransaction *, nsresult) override; \ |
160 | | MOZ_MUST_USE nsresult TakeTransport(nsISocketTransport **, \ |
161 | | nsIAsyncInputStream **, \ |
162 | | nsIAsyncOutputStream **) override; \ |
163 | | bool IsPersistent() override; \ |
164 | | bool IsReused() override; \ |
165 | | void DontReuse() override; \ |
166 | | MOZ_MUST_USE nsresult PushBack(const char *, uint32_t) override; \ |
167 | | already_AddRefed<nsHttpConnection> TakeHttpConnection() override; \ |
168 | | already_AddRefed<nsHttpConnection> HttpConnection() override; \ |
169 | | void TopLevelOuterContentWindowIdChanged(uint64_t windowId) override; \ |
170 | | /* \ |
171 | | Thes methods below have automatic definitions that just forward the \ |
172 | | function to a lower level connection object \ |
173 | | */ \ |
174 | | void GetConnectionInfo(nsHttpConnectionInfo **result) \ |
175 | | override \ |
176 | 0 | { \ |
177 | 0 | if (!(fwdObject)) { \ |
178 | 0 | *result = nullptr; \ |
179 | 0 | return; \ |
180 | 0 | } \ |
181 | 0 | return (fwdObject)->GetConnectionInfo(result); \ |
182 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::GetConnectionInfo(mozilla::net::nsHttpConnectionInfo**) Unexecuted instantiation: mozilla::net::ConnectionHandle::GetConnectionInfo(mozilla::net::nsHttpConnectionInfo**) |
183 | | void GetSecurityInfo(nsISupports **result) override \ |
184 | 0 | { \ |
185 | 0 | if (!(fwdObject)) { \ |
186 | 0 | *result = nullptr; \ |
187 | 0 | return; \ |
188 | 0 | } \ |
189 | 0 | return (fwdObject)->GetSecurityInfo(result); \ |
190 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::GetSecurityInfo(nsISupports**) Unexecuted instantiation: mozilla::net::ConnectionHandle::GetSecurityInfo(nsISupports**) |
191 | | MOZ_MUST_USE nsresult ResumeSend() override \ |
192 | 0 | { \ |
193 | 0 | if (!(fwdObject)) \ |
194 | 0 | return NS_ERROR_FAILURE; \ |
195 | 0 | return (fwdObject)->ResumeSend(); \ |
196 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::ResumeSend() Unexecuted instantiation: mozilla::net::ConnectionHandle::ResumeSend() |
197 | | MOZ_MUST_USE nsresult ResumeRecv() override \ |
198 | 0 | { \ |
199 | 0 | if (!(fwdObject)) \ |
200 | 0 | return NS_ERROR_FAILURE; \ |
201 | 0 | return (fwdObject)->ResumeRecv(); \ |
202 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::ResumeRecv() Unexecuted instantiation: mozilla::net::ConnectionHandle::ResumeRecv() |
203 | | MOZ_MUST_USE nsresult ForceSend() override \ |
204 | 0 | { \ |
205 | 0 | if (!(fwdObject)) \ |
206 | 0 | return NS_ERROR_FAILURE; \ |
207 | 0 | return (fwdObject)->ForceSend(); \ |
208 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::ForceSend() Unexecuted instantiation: mozilla::net::ConnectionHandle::ForceSend() |
209 | | MOZ_MUST_USE nsresult ForceRecv() override \ |
210 | 0 | { \ |
211 | 0 | if (!(fwdObject)) \ |
212 | 0 | return NS_ERROR_FAILURE; \ |
213 | 0 | return (fwdObject)->ForceRecv(); \ |
214 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::ForceRecv() Unexecuted instantiation: mozilla::net::ConnectionHandle::ForceRecv() |
215 | | nsISocketTransport *Transport() \ |
216 | | override \ |
217 | 0 | { \ |
218 | 0 | if (!(fwdObject)) \ |
219 | 0 | return nullptr; \ |
220 | 0 | return (fwdObject)->Transport(); \ |
221 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::Transport() Unexecuted instantiation: mozilla::net::ConnectionHandle::Transport() |
222 | | HttpVersion Version() override \ |
223 | 0 | { \ |
224 | 0 | return (fwdObject) ? \ |
225 | 0 | (fwdObject)->Version() : \ |
226 | 0 | mozilla::net::HttpVersion::UNKNOWN; \ |
227 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::Version() Unexecuted instantiation: mozilla::net::ConnectionHandle::Version() |
228 | | bool IsProxyConnectInProgress() override \ |
229 | 0 | { \ |
230 | 0 | return (!fwdObject) ? false : \ |
231 | 0 | (fwdObject)->IsProxyConnectInProgress(); \ |
232 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::IsProxyConnectInProgress() Unexecuted instantiation: mozilla::net::ConnectionHandle::IsProxyConnectInProgress() |
233 | | bool LastTransactionExpectedNoContent() override \ |
234 | 0 | { \ |
235 | 0 | return (!fwdObject) ? false : \ |
236 | 0 | (fwdObject)->LastTransactionExpectedNoContent(); \ |
237 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::LastTransactionExpectedNoContent() Unexecuted instantiation: mozilla::net::ConnectionHandle::LastTransactionExpectedNoContent() |
238 | | void SetLastTransactionExpectedNoContent(bool val) \ |
239 | | override \ |
240 | 0 | { \ |
241 | 0 | if (fwdObject) \ |
242 | 0 | (fwdObject)->SetLastTransactionExpectedNoContent(val); \ |
243 | 0 | } \ Unexecuted instantiation: mozilla::net::Http2Session::SetLastTransactionExpectedNoContent(bool) Unexecuted instantiation: mozilla::net::ConnectionHandle::SetLastTransactionExpectedNoContent(bool) |
244 | | int64_t BytesWritten() override \ |
245 | 0 | { return fwdObject ? (fwdObject)->BytesWritten() : 0; } \ Unexecuted instantiation: mozilla::net::Http2Session::BytesWritten() Unexecuted instantiation: mozilla::net::ConnectionHandle::BytesWritten() |
246 | | void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) \ |
247 | | override \ |
248 | 0 | { \ |
249 | 0 | if (fwdObject) \ |
250 | 0 | (fwdObject)->SetSecurityCallbacks(aCallbacks); \ |
251 | 0 | } Unexecuted instantiation: mozilla::net::Http2Session::SetSecurityCallbacks(nsIInterfaceRequestor*) Unexecuted instantiation: mozilla::net::ConnectionHandle::SetSecurityCallbacks(nsIInterfaceRequestor*) |
252 | | |
253 | | // ThrottleResponse deliberately ommited since we want different implementation |
254 | | // for h1 and h2 connections. |
255 | | |
256 | | } // namespace net |
257 | | } // namespace mozilla |
258 | | |
259 | | #endif // nsAHttpConnection_h__ |