/src/mozilla-central/netwerk/protocol/http/nsHttpHandler.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef nsHttpHandler_h__ |
7 | | #define nsHttpHandler_h__ |
8 | | |
9 | | #include "nsHttp.h" |
10 | | #include "nsHttpAuthCache.h" |
11 | | #include "nsHttpConnectionMgr.h" |
12 | | #include "ASpdySession.h" |
13 | | |
14 | | #include "mozilla/Mutex.h" |
15 | | #include "mozilla/StaticPtr.h" |
16 | | #include "mozilla/TimeStamp.h" |
17 | | #include "nsString.h" |
18 | | #include "nsCOMPtr.h" |
19 | | #include "nsWeakReference.h" |
20 | | |
21 | | #include "nsIHttpProtocolHandler.h" |
22 | | #include "nsIObserver.h" |
23 | | #include "nsISpeculativeConnect.h" |
24 | | |
25 | | class nsIHttpChannel; |
26 | | class nsIPrefBranch; |
27 | | class nsICancelable; |
28 | | class nsICookieService; |
29 | | class nsIIOService; |
30 | | class nsIRequestContextService; |
31 | | class nsISiteSecurityService; |
32 | | class nsIStreamConverterService; |
33 | | |
34 | | |
35 | | namespace mozilla { |
36 | | namespace net { |
37 | | |
38 | | bool OnSocketThread(); |
39 | | |
40 | | class ATokenBucketEvent; |
41 | | class EventTokenBucket; |
42 | | class Tickler; |
43 | | class nsHttpConnection; |
44 | | class nsHttpConnectionInfo; |
45 | | class nsHttpTransaction; |
46 | | class AltSvcMapping; |
47 | | |
48 | | enum FrameCheckLevel { |
49 | | FRAMECHECK_LAX, |
50 | | FRAMECHECK_BARELY, |
51 | | FRAMECHECK_STRICT |
52 | | }; |
53 | | |
54 | | //----------------------------------------------------------------------------- |
55 | | // nsHttpHandler - protocol handler for HTTP and HTTPS |
56 | | //----------------------------------------------------------------------------- |
57 | | |
58 | | class nsHttpHandler final : public nsIHttpProtocolHandler |
59 | | , public nsIObserver |
60 | | , public nsSupportsWeakReference |
61 | | , public nsISpeculativeConnect |
62 | | { |
63 | | public: |
64 | | NS_DECL_THREADSAFE_ISUPPORTS |
65 | | NS_DECL_NSIPROTOCOLHANDLER |
66 | | NS_DECL_NSIPROXIEDPROTOCOLHANDLER |
67 | | NS_DECL_NSIHTTPPROTOCOLHANDLER |
68 | | NS_DECL_NSIOBSERVER |
69 | | NS_DECL_NSISPECULATIVECONNECT |
70 | | |
71 | | static already_AddRefed<nsHttpHandler> GetInstance(); |
72 | | |
73 | | MOZ_MUST_USE nsresult AddStandardRequestHeaders(nsHttpRequestHead *, |
74 | | bool isSecure); |
75 | | MOZ_MUST_USE nsresult AddConnectionHeader(nsHttpRequestHead *, |
76 | | uint32_t capabilities); |
77 | | bool IsAcceptableEncoding(const char *encoding, bool isSecure); |
78 | | |
79 | | const nsCString& UserAgent(); |
80 | | |
81 | 0 | enum HttpVersion HttpVersion() { return mHttpVersion; } |
82 | 0 | enum HttpVersion ProxyHttpVersion() { return mProxyHttpVersion; } |
83 | 0 | uint8_t ReferrerLevel() { return mReferrerLevel; } |
84 | 0 | bool SpoofReferrerSource() { return mSpoofReferrerSource; } |
85 | 0 | bool HideOnionReferrerSource() { return mHideOnionReferrerSource; } |
86 | 0 | uint8_t ReferrerTrimmingPolicy() { return mReferrerTrimmingPolicy; } |
87 | 0 | uint8_t ReferrerXOriginTrimmingPolicy() { |
88 | 0 | return mReferrerXOriginTrimmingPolicy; |
89 | 0 | } |
90 | 0 | uint8_t ReferrerXOriginPolicy() { return mReferrerXOriginPolicy; } |
91 | 0 | uint8_t RedirectionLimit() { return mRedirectionLimit; } |
92 | 0 | PRIntervalTime IdleTimeout() { return mIdleTimeout; } |
93 | 0 | PRIntervalTime SpdyTimeout() { return mSpdyTimeout; } |
94 | 0 | PRIntervalTime ResponseTimeout() { |
95 | 0 | return mResponseTimeoutEnabled ? mResponseTimeout : 0; |
96 | 0 | } |
97 | 0 | PRIntervalTime ResponseTimeoutEnabled() { return mResponseTimeoutEnabled; } |
98 | 0 | uint32_t NetworkChangedTimeout() { return mNetworkChangedTimeout; } |
99 | 0 | uint16_t MaxRequestAttempts() { return mMaxRequestAttempts; } |
100 | 0 | const char *DefaultSocketType() { return mDefaultSocketType.IsVoid() ? nullptr : mDefaultSocketType.get(); } |
101 | 0 | uint32_t PhishyUserPassLength() { return mPhishyUserPassLength; } |
102 | 0 | uint8_t GetQoSBits() { return mQoSBits; } |
103 | 0 | uint16_t GetIdleSynTimeout() { return mIdleSynTimeout; } |
104 | 0 | uint16_t GetFallbackSynTimeout() { return mFallbackSynTimeout; } |
105 | 0 | bool FastFallbackToIPv4() { return mFastFallbackToIPv4; } |
106 | | uint32_t MaxSocketCount(); |
107 | 0 | bool EnforceAssocReq() { return mEnforceAssocReq; } |
108 | | |
109 | 0 | bool IsPersistentHttpsCachingEnabled() { return mEnablePersistentHttpsCaching; } |
110 | 0 | bool IsTelemetryEnabled() { return mTelemetryEnabled; } |
111 | 0 | bool AllowExperiments() { return mTelemetryEnabled && mAllowExperiments; } |
112 | | |
113 | 0 | bool IsSpdyEnabled() { return mEnableSpdy; } |
114 | 0 | bool IsHttp2Enabled() { return mHttp2Enabled; } |
115 | 0 | bool EnforceHttp2TlsProfile() { return mEnforceHttp2TlsProfile; } |
116 | 0 | bool CoalesceSpdy() { return mCoalesceSpdy; } |
117 | 0 | bool UseSpdyPersistentSettings() { return mSpdyPersistentSettings; } |
118 | 0 | uint32_t SpdySendingChunkSize() { return mSpdySendingChunkSize; } |
119 | 0 | uint32_t SpdySendBufferSize() { return mSpdySendBufferSize; } |
120 | 0 | uint32_t SpdyPushAllowance() { return mSpdyPushAllowance; } |
121 | 0 | uint32_t SpdyPullAllowance() { return mSpdyPullAllowance; } |
122 | 0 | uint32_t DefaultSpdyConcurrent() { return mDefaultSpdyConcurrent; } |
123 | 0 | PRIntervalTime SpdyPingThreshold() { return mSpdyPingThreshold; } |
124 | 0 | PRIntervalTime SpdyPingTimeout() { return mSpdyPingTimeout; } |
125 | 0 | bool AllowPush() { return mAllowPush; } |
126 | 0 | bool AllowAltSvc() { return mEnableAltSvc; } |
127 | 0 | bool AllowAltSvcOE() { return mEnableAltSvcOE; } |
128 | 0 | bool AllowOriginExtension() { return mEnableOriginExtension; } |
129 | 0 | uint32_t ConnectTimeout() { return mConnectTimeout; } |
130 | 0 | uint32_t TLSHandshakeTimeout() { return mTLSHandshakeTimeout; } |
131 | 0 | uint32_t ParallelSpeculativeConnectLimit() { return mParallelSpeculativeConnectLimit; } |
132 | 0 | bool CriticalRequestPrioritization() { return mCriticalRequestPrioritization; } |
133 | 0 | bool UseH2Deps() { return mUseH2Deps; } |
134 | | |
135 | 0 | uint32_t MaxConnectionsPerOrigin() { return mMaxPersistentConnectionsPerServer; } |
136 | 0 | bool UseRequestTokenBucket() { return mRequestTokenBucketEnabled; } |
137 | 0 | uint16_t RequestTokenBucketMinParallelism() { return mRequestTokenBucketMinParallelism; } |
138 | 1 | uint32_t RequestTokenBucketHz() { return mRequestTokenBucketHz; } |
139 | 1 | uint32_t RequestTokenBucketBurst() {return mRequestTokenBucketBurst; } |
140 | | |
141 | 0 | bool PromptTempRedirect() { return mPromptTempRedirect; } |
142 | 0 | bool IsUrgentStartEnabled() { return mUrgentStartEnabled; } |
143 | 0 | bool IsTailBlockingEnabled() { return mTailBlockingEnabled; } |
144 | 0 | uint32_t TailBlockingDelayQuantum(bool aAfterDOMContentLoaded) { |
145 | 0 | return aAfterDOMContentLoaded ? mTailDelayQuantumAfterDCL : mTailDelayQuantum; |
146 | 0 | } |
147 | 0 | uint32_t TailBlockingDelayMax() { return mTailDelayMax; } |
148 | 0 | uint32_t TailBlockingTotalMax() { return mTailTotalMax; } |
149 | | |
150 | 0 | uint32_t ThrottlingReadLimit() { return mThrottleVersion == 1 ? 0 : mThrottleReadLimit; } |
151 | 0 | int32_t SendWindowSize() { return mSendWindowSize * 1024; } |
152 | | |
153 | | // TCP Keepalive configuration values. |
154 | | |
155 | | // Returns true if TCP keepalive should be enabled for short-lived conns. |
156 | 0 | bool TCPKeepaliveEnabledForShortLivedConns() { |
157 | 0 | return mTCPKeepaliveShortLivedEnabled; |
158 | 0 | } |
159 | | // Return time (secs) that a connection is consider short lived (for TCP |
160 | | // keepalive purposes). After this time, the connection is long-lived. |
161 | 0 | int32_t GetTCPKeepaliveShortLivedTime() { |
162 | 0 | return mTCPKeepaliveShortLivedTimeS; |
163 | 0 | } |
164 | | // Returns time (secs) before first TCP keepalive probes should be sent; |
165 | | // same time used between successful keepalive probes. |
166 | 0 | int32_t GetTCPKeepaliveShortLivedIdleTime() { |
167 | 0 | return mTCPKeepaliveShortLivedIdleTimeS; |
168 | 0 | } |
169 | | |
170 | | // Returns true if TCP keepalive should be enabled for long-lived conns. |
171 | 0 | bool TCPKeepaliveEnabledForLongLivedConns() { |
172 | 0 | return mTCPKeepaliveLongLivedEnabled; |
173 | 0 | } |
174 | | // Returns time (secs) before first TCP keepalive probes should be sent; |
175 | | // same time used between successful keepalive probes. |
176 | 0 | int32_t GetTCPKeepaliveLongLivedIdleTime() { |
177 | 0 | return mTCPKeepaliveLongLivedIdleTimeS; |
178 | 0 | } |
179 | | |
180 | | bool UseFastOpen() |
181 | 0 | { |
182 | 0 | return mUseFastOpen && mFastOpenSupported && |
183 | 0 | (mFastOpenStallsCounter < mFastOpenStallsLimit) && |
184 | 0 | (mFastOpenConsecutiveFailureCounter < mFastOpenConsecutiveFailureLimit); |
185 | 0 | } |
186 | | // If one of tcp connections return PR_NOT_TCP_SOCKET_ERROR while trying |
187 | | // fast open, it means that Fast Open is turned off so we will not try again |
188 | | // until a restart. This is only on Linux. |
189 | 0 | void SetFastOpenNotSupported() { mFastOpenSupported = false; } |
190 | | |
191 | | void IncrementFastOpenConsecutiveFailureCounter(); |
192 | | |
193 | | void ResetFastOpenConsecutiveFailureCounter() |
194 | 0 | { |
195 | 0 | mFastOpenConsecutiveFailureCounter = 0; |
196 | 0 | } |
197 | | |
198 | | void IncrementFastOpenStallsCounter(); |
199 | 0 | uint32_t CheckIfConnectionIsStalledOnlyIfIdleForThisAmountOfSeconds() { |
200 | 0 | return mFastOpenStallsIdleTime; |
201 | 0 | } |
202 | 0 | uint32_t FastOpenStallsTimeout() { |
203 | 0 | return mFastOpenStallsTimeout; |
204 | 0 | } |
205 | | |
206 | | // returns the HTTP framing check level preference, as controlled with |
207 | | // network.http.enforce-framing.http1 and network.http.enforce-framing.soft |
208 | 0 | FrameCheckLevel GetEnforceH1Framing() { return mEnforceH1Framing; } |
209 | | |
210 | 0 | nsHttpAuthCache *AuthCache(bool aPrivate) { |
211 | 0 | return aPrivate ? &mPrivateAuthCache : &mAuthCache; |
212 | 0 | } |
213 | 0 | nsHttpConnectionMgr *ConnMgr() { return mConnMgr; } |
214 | | |
215 | | // cache support |
216 | 0 | uint32_t GenerateUniqueID() { return ++mLastUniqueID; } |
217 | 0 | uint32_t SessionStartTime() { return mSessionStartTime; } |
218 | | |
219 | | // |
220 | | // Connection management methods: |
221 | | // |
222 | | // - the handler only owns idle connections; it does not own active |
223 | | // connections. |
224 | | // |
225 | | // - the handler keeps a count of active connections to enforce the |
226 | | // steady-state max-connections pref. |
227 | | // |
228 | | |
229 | | // Called to kick-off a new transaction, by default the transaction |
230 | | // will be put on the pending transaction queue if it cannot be |
231 | | // initiated at this time. Callable from any thread. |
232 | | MOZ_MUST_USE nsresult InitiateTransaction(nsHttpTransaction *trans, |
233 | | int32_t priority) |
234 | 0 | { |
235 | 0 | return mConnMgr->AddTransaction(trans, priority); |
236 | 0 | } |
237 | | |
238 | | // Called to change the priority of an existing transaction that has |
239 | | // already been initiated. |
240 | | MOZ_MUST_USE nsresult RescheduleTransaction(nsHttpTransaction *trans, |
241 | | int32_t priority) |
242 | 0 | { |
243 | 0 | return mConnMgr->RescheduleTransaction(trans, priority); |
244 | 0 | } |
245 | | |
246 | | void UpdateClassOfServiceOnTransaction(nsHttpTransaction *trans, |
247 | | uint32_t classOfService) |
248 | 0 | { |
249 | 0 | mConnMgr->UpdateClassOfServiceOnTransaction(trans, classOfService); |
250 | 0 | } |
251 | | |
252 | | // Called to cancel a transaction, which may or may not be assigned to |
253 | | // a connection. Callable from any thread. |
254 | | MOZ_MUST_USE nsresult CancelTransaction(nsHttpTransaction *trans, |
255 | | nsresult reason) |
256 | 0 | { |
257 | 0 | return mConnMgr->CancelTransaction(trans, reason); |
258 | 0 | } |
259 | | |
260 | | // Called when a connection is done processing a transaction. Callable |
261 | | // from any thread. |
262 | | MOZ_MUST_USE nsresult ReclaimConnection(nsHttpConnection *conn) |
263 | 0 | { |
264 | 0 | return mConnMgr->ReclaimConnection(conn); |
265 | 0 | } |
266 | | |
267 | | MOZ_MUST_USE nsresult ProcessPendingQ(nsHttpConnectionInfo *cinfo) |
268 | 0 | { |
269 | 0 | return mConnMgr->ProcessPendingQ(cinfo); |
270 | 0 | } |
271 | | |
272 | | MOZ_MUST_USE nsresult ProcessPendingQ() |
273 | 0 | { |
274 | 0 | return mConnMgr->ProcessPendingQ(); |
275 | 0 | } |
276 | | |
277 | | MOZ_MUST_USE nsresult GetSocketThreadTarget(nsIEventTarget **target) |
278 | 0 | { |
279 | 0 | return mConnMgr->GetSocketThreadTarget(target); |
280 | 0 | } |
281 | | |
282 | | MOZ_MUST_USE nsresult SpeculativeConnect(nsHttpConnectionInfo *ci, |
283 | | nsIInterfaceRequestor *callbacks, |
284 | | uint32_t caps = 0) |
285 | 0 | { |
286 | 0 | TickleWifi(callbacks); |
287 | 0 | return mConnMgr->SpeculativeConnect(ci, callbacks, caps); |
288 | 0 | } |
289 | | |
290 | | // Alternate Services Maps are main thread only |
291 | | void UpdateAltServiceMapping(AltSvcMapping *map, |
292 | | nsProxyInfo *proxyInfo, |
293 | | nsIInterfaceRequestor *callbacks, |
294 | | uint32_t caps, |
295 | | const OriginAttributes &originAttributes) |
296 | 0 | { |
297 | 0 | mConnMgr->UpdateAltServiceMapping(map, proxyInfo, callbacks, caps, |
298 | 0 | originAttributes); |
299 | 0 | } |
300 | | |
301 | | already_AddRefed<AltSvcMapping> GetAltServiceMapping(const nsACString &scheme, |
302 | | const nsACString &host, |
303 | | int32_t port, bool pb, |
304 | | const OriginAttributes &originAttributes) |
305 | 0 | { |
306 | 0 | return mConnMgr->GetAltServiceMapping(scheme, host, port, pb, originAttributes); |
307 | 0 | } |
308 | | |
309 | | // |
310 | | // The HTTP handler caches pointers to specific XPCOM services, and |
311 | | // provides the following helper routines for accessing those services: |
312 | | // |
313 | | MOZ_MUST_USE nsresult GetStreamConverterService(nsIStreamConverterService **); |
314 | | MOZ_MUST_USE nsresult GetIOService(nsIIOService** service); |
315 | | nsICookieService * GetCookieService(); // not addrefed |
316 | | nsISiteSecurityService * GetSSService(); |
317 | | |
318 | | // callable from socket thread only |
319 | | uint32_t Get32BitsOfPseudoRandom(); |
320 | | |
321 | | // Called by the channel synchronously during asyncOpen |
322 | | void OnOpeningRequest(nsIHttpChannel *chan) |
323 | 0 | { |
324 | 0 | NotifyObservers(chan, NS_HTTP_ON_OPENING_REQUEST_TOPIC); |
325 | 0 | } |
326 | | |
327 | | // Called by the channel before writing a request |
328 | | void OnModifyRequest(nsIHttpChannel *chan) |
329 | 0 | { |
330 | 0 | NotifyObservers(chan, NS_HTTP_ON_MODIFY_REQUEST_TOPIC); |
331 | 0 | } |
332 | | |
333 | | // Called by the channel before writing a request |
334 | | void OnStopRequest(nsIHttpChannel *chan) |
335 | 0 | { |
336 | 0 | NotifyObservers(chan, NS_HTTP_ON_STOP_REQUEST_TOPIC); |
337 | 0 | } |
338 | | |
339 | | // Called by the channel and cached in the loadGroup |
340 | | void OnUserAgentRequest(nsIHttpChannel *chan) |
341 | 0 | { |
342 | 0 | NotifyObservers(chan, NS_HTTP_ON_USERAGENT_REQUEST_TOPIC); |
343 | 0 | } |
344 | | |
345 | | // Called by the channel before setting up the transaction |
346 | | void OnBeforeConnect(nsIHttpChannel *chan) |
347 | 0 | { |
348 | 0 | NotifyObservers(chan, NS_HTTP_ON_BEFORE_CONNECT_TOPIC); |
349 | 0 | } |
350 | | |
351 | | // Called by the channel once headers are available |
352 | | void OnExamineResponse(nsIHttpChannel *chan) |
353 | 0 | { |
354 | 0 | NotifyObservers(chan, NS_HTTP_ON_EXAMINE_RESPONSE_TOPIC); |
355 | 0 | } |
356 | | |
357 | | // Called by the channel once headers have been merged with cached headers |
358 | | void OnExamineMergedResponse(nsIHttpChannel *chan) |
359 | 0 | { |
360 | 0 | NotifyObservers(chan, NS_HTTP_ON_EXAMINE_MERGED_RESPONSE_TOPIC); |
361 | 0 | } |
362 | | |
363 | | // Called by channels before a redirect happens. This notifies both the |
364 | | // channel's and the global redirect observers. |
365 | | MOZ_MUST_USE nsresult AsyncOnChannelRedirect( |
366 | | nsIChannel* oldChan, |
367 | | nsIChannel* newChan, |
368 | | uint32_t flags, |
369 | | nsIEventTarget* mainThreadEventTarget = nullptr); |
370 | | |
371 | | // Called by the channel when the response is read from the cache without |
372 | | // communicating with the server. |
373 | | void OnExamineCachedResponse(nsIHttpChannel *chan) |
374 | 0 | { |
375 | 0 | NotifyObservers(chan, NS_HTTP_ON_EXAMINE_CACHED_RESPONSE_TOPIC); |
376 | 0 | } |
377 | | |
378 | | // Generates the host:port string for use in the Host: header as well as the |
379 | | // CONNECT line for proxies. This handles IPv6 literals correctly. |
380 | | static MOZ_MUST_USE nsresult GenerateHostPort(const nsCString& host, |
381 | | int32_t port, |
382 | | nsACString& hostLine); |
383 | | |
384 | | |
385 | 0 | SpdyInformation *SpdyInfo() { return &mSpdyInfo; } |
386 | 0 | bool IsH2MandatorySuiteEnabled() { return mH2MandatorySuiteEnabled; } |
387 | | |
388 | | // returns true in between Init and Shutdown states |
389 | 0 | bool Active() { return mHandlerActive; } |
390 | | |
391 | | nsIRequestContextService *GetRequestContextService() |
392 | 0 | { |
393 | 0 | return mRequestContextService.get(); |
394 | 0 | } |
395 | | |
396 | | void ShutdownConnectionManager(); |
397 | | |
398 | | uint32_t DefaultHpackBuffer() const |
399 | 0 | { |
400 | 0 | return mDefaultHpackBuffer; |
401 | 0 | } |
402 | | |
403 | | uint32_t MaxHttpResponseHeaderSize() const |
404 | 0 | { |
405 | 0 | return mMaxHttpResponseHeaderSize; |
406 | 0 | } |
407 | | |
408 | | float FocusedWindowTransactionRatio() const |
409 | 0 | { |
410 | 0 | return mFocusedWindowTransactionRatio; |
411 | 0 | } |
412 | | |
413 | | bool ActiveTabPriority() const |
414 | 0 | { |
415 | 0 | return mActiveTabPriority; |
416 | 0 | } |
417 | | |
418 | | // Called when an optimization feature affecting active vs background tab load |
419 | | // took place. Called only on the parent process and only updates |
420 | | // mLastActiveTabLoadOptimizationHit timestamp to now. |
421 | | void NotifyActiveTabLoadOptimization(); |
422 | | TimeStamp const GetLastActiveTabLoadOptimizationHit(); |
423 | | void SetLastActiveTabLoadOptimizationHit(TimeStamp const &when); |
424 | | bool IsBeforeLastActiveTabLoadOptimization(TimeStamp const &when); |
425 | | |
426 | | private: |
427 | | nsHttpHandler(); |
428 | | |
429 | | virtual ~nsHttpHandler(); |
430 | | |
431 | | MOZ_MUST_USE nsresult Init(); |
432 | | |
433 | | // |
434 | | // Useragent/prefs helper methods |
435 | | // |
436 | | void BuildUserAgent(); |
437 | | void InitUserAgentComponents(); |
438 | | void PrefsChanged(const char *pref); |
439 | | |
440 | | MOZ_MUST_USE nsresult SetAccept(const char *); |
441 | | MOZ_MUST_USE nsresult SetAcceptLanguages(); |
442 | | MOZ_MUST_USE nsresult SetAcceptEncodings(const char *, bool mIsSecure); |
443 | | |
444 | | MOZ_MUST_USE nsresult InitConnectionMgr(); |
445 | | |
446 | | void NotifyObservers(nsIHttpChannel *chan, const char *event); |
447 | | |
448 | | void SetFastOpenOSSupport(); |
449 | | |
450 | | void EnsureUAOverridesInit(); |
451 | | private: |
452 | | |
453 | | // cached services |
454 | | nsMainThreadPtrHandle<nsIIOService> mIOService; |
455 | | nsMainThreadPtrHandle<nsIStreamConverterService> mStreamConvSvc; |
456 | | nsMainThreadPtrHandle<nsICookieService> mCookieService; |
457 | | nsMainThreadPtrHandle<nsISiteSecurityService> mSSService; |
458 | | |
459 | | // the authentication credentials cache |
460 | | nsHttpAuthCache mAuthCache; |
461 | | nsHttpAuthCache mPrivateAuthCache; |
462 | | |
463 | | // the connection manager |
464 | | RefPtr<nsHttpConnectionMgr> mConnMgr; |
465 | | |
466 | | // |
467 | | // prefs |
468 | | // |
469 | | |
470 | | enum HttpVersion mHttpVersion; |
471 | | enum HttpVersion mProxyHttpVersion; |
472 | | uint32_t mCapabilities; |
473 | | uint8_t mReferrerLevel; |
474 | | uint8_t mSpoofReferrerSource; |
475 | | uint8_t mHideOnionReferrerSource; |
476 | | uint8_t mReferrerTrimmingPolicy; |
477 | | uint8_t mReferrerXOriginTrimmingPolicy; |
478 | | uint8_t mReferrerXOriginPolicy; |
479 | | |
480 | | bool mFastFallbackToIPv4; |
481 | | PRIntervalTime mIdleTimeout; |
482 | | PRIntervalTime mSpdyTimeout; |
483 | | PRIntervalTime mResponseTimeout; |
484 | | bool mResponseTimeoutEnabled; |
485 | | uint32_t mNetworkChangedTimeout; // milliseconds |
486 | | uint16_t mMaxRequestAttempts; |
487 | | uint16_t mMaxRequestDelay; |
488 | | uint16_t mIdleSynTimeout; |
489 | | uint16_t mFallbackSynTimeout; // seconds |
490 | | |
491 | | bool mH2MandatorySuiteEnabled; |
492 | | uint16_t mMaxUrgentExcessiveConns; |
493 | | uint16_t mMaxConnections; |
494 | | uint8_t mMaxPersistentConnectionsPerServer; |
495 | | uint8_t mMaxPersistentConnectionsPerProxy; |
496 | | |
497 | | bool mThrottleEnabled; |
498 | | uint32_t mThrottleVersion; |
499 | | uint32_t mThrottleSuspendFor; |
500 | | uint32_t mThrottleResumeFor; |
501 | | uint32_t mThrottleReadLimit; |
502 | | uint32_t mThrottleReadInterval; |
503 | | uint32_t mThrottleHoldTime; |
504 | | uint32_t mThrottleMaxTime; |
505 | | |
506 | | int32_t mSendWindowSize; |
507 | | |
508 | | bool mUrgentStartEnabled; |
509 | | bool mTailBlockingEnabled; |
510 | | uint32_t mTailDelayQuantum; |
511 | | uint32_t mTailDelayQuantumAfterDCL; |
512 | | uint32_t mTailDelayMax; |
513 | | uint32_t mTailTotalMax; |
514 | | |
515 | | uint8_t mRedirectionLimit; |
516 | | |
517 | | // we'll warn the user if we load an URL containing a userpass field |
518 | | // unless its length is less than this threshold. this warning is |
519 | | // intended to protect the user against spoofing attempts that use |
520 | | // the userpass field of the URL to obscure the actual origin server. |
521 | | uint8_t mPhishyUserPassLength; |
522 | | |
523 | | uint8_t mQoSBits; |
524 | | |
525 | | bool mEnforceAssocReq; |
526 | | |
527 | | nsCString mAccept; |
528 | | nsCString mAcceptLanguages; |
529 | | nsCString mHttpAcceptEncodings; |
530 | | nsCString mHttpsAcceptEncodings; |
531 | | |
532 | | nsCString mDefaultSocketType; |
533 | | |
534 | | // cache support |
535 | | uint32_t mLastUniqueID; |
536 | | uint32_t mSessionStartTime; |
537 | | |
538 | | // useragent components |
539 | | nsCString mLegacyAppName; |
540 | | nsCString mLegacyAppVersion; |
541 | | nsCString mPlatform; |
542 | | nsCString mOscpu; |
543 | | nsCString mMisc; |
544 | | nsCString mProduct; |
545 | | nsCString mProductSub; |
546 | | nsCString mAppName; |
547 | | nsCString mAppVersion; |
548 | | nsCString mCompatFirefox; |
549 | | bool mCompatFirefoxEnabled; |
550 | | nsCString mCompatDevice; |
551 | | nsCString mDeviceModelId; |
552 | | |
553 | | nsCString mUserAgent; |
554 | | nsCString mSpoofedUserAgent; |
555 | | nsCString mUserAgentOverride; |
556 | | bool mUserAgentIsDirty; // true if mUserAgent should be rebuilt |
557 | | bool mAcceptLanguagesIsDirty; |
558 | | |
559 | | |
560 | | bool mPromptTempRedirect; |
561 | | |
562 | | // Persistent HTTPS caching flag |
563 | | bool mEnablePersistentHttpsCaching; |
564 | | |
565 | | // For broadcasting tracking preference |
566 | | bool mDoNotTrackEnabled; |
567 | | |
568 | | // for broadcasting safe hint; |
569 | | bool mSafeHintEnabled; |
570 | | bool mParentalControlEnabled; |
571 | | |
572 | | // true in between init and shutdown states |
573 | | Atomic<bool, Relaxed> mHandlerActive; |
574 | | |
575 | | // Whether telemetry is reported or not |
576 | | uint32_t mTelemetryEnabled : 1; |
577 | | |
578 | | // The value of network.allow-experiments |
579 | | uint32_t mAllowExperiments : 1; |
580 | | |
581 | | // The value of 'hidden' network.http.debug-observations : 1; |
582 | | uint32_t mDebugObservations : 1; |
583 | | |
584 | | uint32_t mEnableSpdy : 1; |
585 | | uint32_t mHttp2Enabled : 1; |
586 | | uint32_t mUseH2Deps : 1; |
587 | | uint32_t mEnforceHttp2TlsProfile : 1; |
588 | | uint32_t mCoalesceSpdy : 1; |
589 | | uint32_t mSpdyPersistentSettings : 1; |
590 | | uint32_t mAllowPush : 1; |
591 | | uint32_t mEnableAltSvc : 1; |
592 | | uint32_t mEnableAltSvcOE : 1; |
593 | | uint32_t mEnableOriginExtension : 1; |
594 | | |
595 | | // Try to use SPDY features instead of HTTP/1.1 over SSL |
596 | | SpdyInformation mSpdyInfo; |
597 | | |
598 | | uint32_t mSpdySendingChunkSize; |
599 | | uint32_t mSpdySendBufferSize; |
600 | | uint32_t mSpdyPushAllowance; |
601 | | uint32_t mSpdyPullAllowance; |
602 | | uint32_t mDefaultSpdyConcurrent; |
603 | | PRIntervalTime mSpdyPingThreshold; |
604 | | PRIntervalTime mSpdyPingTimeout; |
605 | | |
606 | | // The maximum amount of time to wait for socket transport to be |
607 | | // established. In milliseconds. |
608 | | uint32_t mConnectTimeout; |
609 | | |
610 | | // The maximum amount of time to wait for a tls handshake to be |
611 | | // established. In milliseconds. |
612 | | uint32_t mTLSHandshakeTimeout; |
613 | | |
614 | | // The maximum number of current global half open sockets allowable |
615 | | // when starting a new speculative connection. |
616 | | uint32_t mParallelSpeculativeConnectLimit; |
617 | | |
618 | | // We may disable speculative connect if the browser has user certificates |
619 | | // installed as that might randomly popup the certificate choosing window. |
620 | | bool mSpeculativeConnectEnabled; |
621 | | |
622 | | // For Rate Pacing of HTTP/1 requests through a netwerk/base/EventTokenBucket |
623 | | // Active requests <= *MinParallelism are not subject to the rate pacing |
624 | | bool mRequestTokenBucketEnabled; |
625 | | uint16_t mRequestTokenBucketMinParallelism; |
626 | | uint32_t mRequestTokenBucketHz; // EventTokenBucket HZ |
627 | | uint32_t mRequestTokenBucketBurst; // EventTokenBucket Burst |
628 | | |
629 | | // Whether or not to block requests for non head js/css items (e.g. media) |
630 | | // while those elements load. |
631 | | bool mCriticalRequestPrioritization; |
632 | | |
633 | | // TCP Keepalive configuration values. |
634 | | |
635 | | // True if TCP keepalive is enabled for short-lived conns. |
636 | | bool mTCPKeepaliveShortLivedEnabled; |
637 | | // Time (secs) indicating how long a conn is considered short-lived. |
638 | | int32_t mTCPKeepaliveShortLivedTimeS; |
639 | | // Time (secs) before first keepalive probe; between successful probes. |
640 | | int32_t mTCPKeepaliveShortLivedIdleTimeS; |
641 | | |
642 | | // True if TCP keepalive is enabled for long-lived conns. |
643 | | bool mTCPKeepaliveLongLivedEnabled; |
644 | | // Time (secs) before first keepalive probe; between successful probes. |
645 | | int32_t mTCPKeepaliveLongLivedIdleTimeS; |
646 | | |
647 | | // if true, generate NS_ERROR_PARTIAL_TRANSFER for h1 responses with |
648 | | // incorrect content lengths or malformed chunked encodings |
649 | | FrameCheckLevel mEnforceH1Framing; |
650 | | |
651 | | nsCOMPtr<nsIRequestContextService> mRequestContextService; |
652 | | |
653 | | // The default size (in bytes) of the HPACK decompressor table. |
654 | | uint32_t mDefaultHpackBuffer; |
655 | | |
656 | | // The max size (in bytes) for received Http response header. |
657 | | uint32_t mMaxHttpResponseHeaderSize; |
658 | | |
659 | | // The ratio for dispatching transactions from the focused window. |
660 | | float mFocusedWindowTransactionRatio; |
661 | | |
662 | | Atomic<bool, Relaxed> mUseFastOpen; |
663 | | Atomic<bool, Relaxed> mFastOpenSupported; |
664 | | uint32_t mFastOpenConsecutiveFailureLimit; |
665 | | uint32_t mFastOpenConsecutiveFailureCounter; |
666 | | uint32_t mFastOpenStallsLimit; |
667 | | uint32_t mFastOpenStallsCounter; |
668 | | uint32_t mFastOpenStallsIdleTime; |
669 | | uint32_t mFastOpenStallsTimeout; |
670 | | |
671 | | // If true, the transactions from active tab will be dispatched first. |
672 | | bool mActiveTabPriority; |
673 | | |
674 | | private: |
675 | | // For Rate Pacing Certain Network Events. Only assign this pointer on |
676 | | // socket thread. |
677 | | void MakeNewRequestTokenBucket(); |
678 | | RefPtr<EventTokenBucket> mRequestTokenBucket; |
679 | | |
680 | | public: |
681 | | // Socket thread only |
682 | | MOZ_MUST_USE nsresult SubmitPacedRequest(ATokenBucketEvent *event, |
683 | | nsICancelable **cancel) |
684 | 0 | { |
685 | 0 | MOZ_ASSERT(OnSocketThread(), "not on socket thread"); |
686 | 0 | if (!mRequestTokenBucket) { |
687 | 0 | return NS_ERROR_NOT_AVAILABLE; |
688 | 0 | } |
689 | 0 | return mRequestTokenBucket->SubmitEvent(event, cancel); |
690 | 0 | } |
691 | | |
692 | | // Socket thread only |
693 | | void SetRequestTokenBucket(EventTokenBucket *aTokenBucket) |
694 | 1 | { |
695 | 1 | MOZ_ASSERT(OnSocketThread(), "not on socket thread"); |
696 | 1 | mRequestTokenBucket = aTokenBucket; |
697 | 1 | } |
698 | | |
699 | | void StopRequestTokenBucket() |
700 | 0 | { |
701 | 0 | MOZ_ASSERT(OnSocketThread(), "not on socket thread"); |
702 | 0 | if (mRequestTokenBucket) { |
703 | 0 | mRequestTokenBucket->Stop(); |
704 | 0 | mRequestTokenBucket = nullptr; |
705 | 0 | } |
706 | 0 | } |
707 | | |
708 | | private: |
709 | | RefPtr<Tickler> mWifiTickler; |
710 | | void TickleWifi(nsIInterfaceRequestor *cb); |
711 | | |
712 | | private: |
713 | | MOZ_MUST_USE nsresult |
714 | | SpeculativeConnectInternal(nsIURI *aURI, |
715 | | nsIPrincipal *aPrincipal, |
716 | | nsIInterfaceRequestor *aCallbacks, |
717 | | bool anonymous); |
718 | | |
719 | | // State for generating channelIds |
720 | | uint32_t mProcessId; |
721 | | uint32_t mNextChannelId; |
722 | | |
723 | | // The last time any of the active tab page load optimization took place. |
724 | | // This is accessed on multiple threads, hence a lock is needed. |
725 | | // On the parent process this is updated to now every time a scheduling |
726 | | // or rate optimization related to the active/background tab is hit. |
727 | | // We carry this value through each http channel's onstoprequest notification |
728 | | // to the parent process. On the content process then we just update this |
729 | | // value from ipc onstoprequest arguments. This is a sufficent way of passing |
730 | | // it down to the content process, since the value will be used only after |
731 | | // onstoprequest notification coming from an http channel. |
732 | | Mutex mLastActiveTabLoadOptimizationLock; |
733 | | TimeStamp mLastActiveTabLoadOptimizationHit; |
734 | | |
735 | | public: |
736 | | MOZ_MUST_USE nsresult NewChannelId(uint64_t& channelId); |
737 | | }; |
738 | | |
739 | | extern StaticRefPtr<nsHttpHandler> gHttpHandler; |
740 | | |
741 | | //----------------------------------------------------------------------------- |
742 | | // nsHttpsHandler - thin wrapper to distinguish the HTTP handler from the |
743 | | // HTTPS handler (even though they share the same impl). |
744 | | //----------------------------------------------------------------------------- |
745 | | |
746 | | class nsHttpsHandler : public nsIHttpProtocolHandler |
747 | | , public nsSupportsWeakReference |
748 | | , public nsISpeculativeConnect |
749 | | { |
750 | 0 | virtual ~nsHttpsHandler() = default; |
751 | | public: |
752 | | // we basically just want to override GetScheme and GetDefaultPort... |
753 | | // all other methods should be forwarded to the nsHttpHandler instance. |
754 | | |
755 | | NS_DECL_THREADSAFE_ISUPPORTS |
756 | | NS_DECL_NSIPROTOCOLHANDLER |
757 | | NS_FORWARD_NSIPROXIEDPROTOCOLHANDLER (gHttpHandler->) |
758 | | NS_FORWARD_NSIHTTPPROTOCOLHANDLER (gHttpHandler->) |
759 | | NS_FORWARD_NSISPECULATIVECONNECT (gHttpHandler->) |
760 | | |
761 | 1 | nsHttpsHandler() = default; |
762 | | |
763 | | MOZ_MUST_USE nsresult Init(); |
764 | | }; |
765 | | |
766 | | } // namespace net |
767 | | } // namespace mozilla |
768 | | |
769 | | #endif // nsHttpHandler_h__ |