blob: 906579d725b2e8e692422d64161195f9bcb93a83 [file] [log] [blame]
[email protected]cf4cae32014-05-27 00:39:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_HTTP_HTTP_NETWORK_SESSION_H_
6#define NET_HTTP_HTTP_NETWORK_SESSION_H_
7
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9#include <stdint.h>
10
avifceb32f62016-10-07 16:30:5211#include <map>
12#include <memory>
[email protected]cf4cae32014-05-27 00:39:1013#include <set>
14#include <string>
rch74da0e1a2016-01-14 02:49:3215#include <unordered_set>
[email protected]cf4cae32014-05-27 00:39:1016#include <vector>
17
maksim.sisov0adf8592016-07-15 06:25:5618#include "base/bind.h"
hajimehoshi8156e7c2016-09-29 06:17:5219#include "base/memory/memory_coordinator_client.h"
maksim.sisov0adf8592016-07-15 06:25:5620#include "base/memory/memory_pressure_monitor.h"
[email protected]cf4cae32014-05-27 00:39:1021#include "base/memory/ref_counted.h"
22#include "base/memory/weak_ptr.h"
gab47aa7da2017-06-02 16:09:4323#include "base/threading/thread_checker.h"
mmenke0d700dd82017-05-26 20:36:1124#include "net/base/host_mapping_rules.h"
[email protected]cf4cae32014-05-27 00:39:1025#include "net/base/host_port_pair.h"
26#include "net/base/net_export.h"
27#include "net/dns/host_resolver.h"
28#include "net/http/http_auth_cache.h"
29#include "net/http/http_stream_factory.h"
rch675757b2016-07-29 16:40:1130#include "net/quic/chromium/quic_stream_factory.h"
[email protected]cf4cae32014-05-27 00:39:1031#include "net/socket/next_proto.h"
bnc8f8f7d302017-04-24 18:08:0632#include "net/spdy/chromium/spdy_session_pool.h"
33#include "net/spdy/core/spdy_protocol.h"
[email protected]cf4cae32014-05-27 00:39:1034#include "net/ssl/ssl_client_auth_cache.h"
35
36namespace base {
37class Value;
xunjieli9f8c5fb52016-12-07 22:59:3338namespace trace_event {
39class ProcessMemoryDump;
40}
[email protected]cf4cae32014-05-27 00:39:1041}
42
43namespace net {
44
estark6f9b3d82016-01-12 21:37:0545class CTPolicyEnforcer;
[email protected]cf4cae32014-05-27 00:39:1046class CertVerifier;
[email protected]6b8a3c742014-07-25 00:25:3547class ChannelIDService;
[email protected]cf4cae32014-05-27 00:39:1048class ClientSocketFactory;
49class ClientSocketPoolManager;
50class CTVerifier;
51class HostResolver;
[email protected]cf4cae32014-05-27 00:39:1052class HttpAuthHandlerFactory;
53class HttpNetworkSessionPeer;
54class HttpProxyClientSocketPool;
55class HttpResponseBodyDrainer;
56class HttpServerProperties;
57class NetLog;
tbansal16196a1e2017-06-09 01:50:0958class NetworkQualityProvider;
rdsmith1d343be52016-10-21 20:37:5059class NetworkThrottleManager;
bengr39e406102014-09-10 23:04:4660class ProxyDelegate;
[email protected]cf4cae32014-05-27 00:39:1061class ProxyService;
62class QuicClock;
63class QuicCryptoClientStreamFactory;
tbansalba8f4112015-09-03 21:57:1964class SocketPerformanceWatcherFactory;
[email protected]cf4cae32014-05-27 00:39:1065class SOCKSClientSocketPool;
66class SSLClientSocketPool;
67class SSLConfigService;
68class TransportClientSocketPool;
69class TransportSecurityState;
70
bnc3171a2432016-12-28 18:40:2671// Specifies the maximum HPACK dynamic table size the server is allowed to set.
72const uint32_t kSpdyMaxHeaderTableSize = 64 * 1024;
73
Bence Béky48c4ddf2017-07-24 23:14:3474// The maximum size of header list that the server is allowed to send.
75const uint32_t kSpdyMaxHeaderListSize = 256 * 1024;
76
bnc3171a2432016-12-28 18:40:2677// Specifies the maximum concurrent streams server could send (via push).
78const uint32_t kSpdyMaxConcurrentPushedStreams = 1000;
79
[email protected]cf4cae32014-05-27 00:39:1080// This class holds session objects used by HttpNetworkTransaction objects.
gab47aa7da2017-06-02 16:09:4381class NET_EXPORT HttpNetworkSession : public base::MemoryCoordinatorClient {
[email protected]cf4cae32014-05-27 00:39:1082 public:
mmenke6ddfbea2017-05-31 21:48:4183 // Self-contained structure with all the simple configuration options
84 // supported by the HttpNetworkSession.
[email protected]cf4cae32014-05-27 00:39:1085 struct NET_EXPORT Params {
86 Params();
vmpstracd23b72016-02-26 21:08:5587 Params(const Params& other);
[email protected]cf4cae32014-05-27 00:39:1088 ~Params();
89
zhongyid7dd2db12017-04-14 17:01:2590 bool enable_server_push_cancellation;
mmenke0d700dd82017-05-26 20:36:1191 HostMappingRules host_mapping_rules;
[email protected]cf4cae32014-05-27 00:39:1092 bool ignore_certificate_errors;
Avi Drissman13fc8932015-12-20 04:40:4693 uint16_t testing_fixed_http_port;
94 uint16_t testing_fixed_https_port;
jrif9b4bec2014-09-15 15:46:5495 bool enable_tcp_fast_open_for_ssl;
rch1546ccd2017-04-20 02:14:2396 bool enable_user_alternate_protocol_ports;
[email protected]cf4cae32014-05-27 00:39:1097
rchd502a302015-10-16 03:57:2198 // Use SPDY ping frames to test for connection health after idle.
[email protected]cf4cae32014-05-27 00:39:1099 bool enable_spdy_ping_based_connection_checking;
bnc3f0118e2016-02-02 15:42:22100 bool enable_http2;
bnc8f0f3b62015-04-08 04:37:23101 size_t spdy_session_max_recv_window_size;
bnc3171a2432016-12-28 18:40:26102 // HTTP/2 connection settings.
103 // Unknown settings will still be sent to the server.
104 SettingsMap http2_settings;
rchd502a302015-10-16 03:57:21105 // Source of time for SPDY connections.
[email protected]cf4cae32014-05-27 00:39:10106 SpdySessionPool::TimeFunc time_func;
bnca86731e2017-04-17 12:31:28107 // Whether to enable HTTP/2 Alt-Svc entries.
108 bool enable_http2_alternative_service;
[email protected]cf4cae32014-05-27 00:39:10109
rchd502a302015-10-16 03:57:21110 // Enables QUIC support.
[email protected]cf4cae32014-05-27 00:39:10111 bool enable_quic;
rch1546ccd2017-04-20 02:14:23112
113 // QUIC runtime configuration options.
114
115 // Versions of QUIC which may be used.
116 QuicVersionVector quic_supported_versions;
117 // User agent description to send in the QUIC handshake.
118 std::string quic_user_agent_id;
119 // Limit on the size of QUIC packets.
120 size_t quic_max_packet_length;
rch1546ccd2017-04-20 02:14:23121 // Maximum number of server configs that are to be stored in
122 // HttpServerProperties, instead of the disk cache.
123 size_t quic_max_server_configs_stored_in_properties;
124 // QUIC will be used for all connections in this set.
125 std::set<HostPortPair> origins_to_force_quic_on;
126 // Set of QUIC tags to send in the handshake's connection options.
127 QuicTagVector quic_connection_options;
Yixin Wang46a425f2017-08-10 23:02:20128 // Set of QUIC tags to send in the handshake's connection options that only
129 // affect the client.
130 QuicTagVector quic_client_connection_options;
rch1546ccd2017-04-20 02:14:23131
132 // Active QUIC experiments
133
rch9ecde09b2017-04-08 00:18:23134 // Marks a QUIC server broken when a connection blackholes after the
135 // handshake is confirmed.
136 bool mark_quic_broken_when_network_blackholes;
rch2f2991c2017-04-13 19:28:17137 // Retry requests which fail with QUIC_PROTOCOL_ERROR, and mark QUIC
138 // broken if the retry succeeds.
139 bool retry_without_alt_svc_on_quic_errors;
jri8c44d692015-10-23 23:53:41140 // If true, all QUIC sessions are closed when any local IP address changes.
141 bool quic_close_sessions_on_ip_change;
zhongyi6ba0f4252016-08-23 05:20:04142 // Specifies QUIC idle connection state lifetime.
rtenneti41c09992015-11-30 18:24:01143 int quic_idle_connection_timeout_seconds;
zhongyidd1439f62016-09-02 02:02:26144 // Specifies the reduced ping timeout subsequent connections should use when
145 // a connection was timed out with open streams.
146 int quic_reduced_ping_timeout_seconds;
jrid36ada62016-02-06 02:42:08147 // If true, active QUIC sessions may be migrated onto a new network when
148 // the platform indicates that the default network is changing.
jri7e636642016-01-14 06:57:08149 bool quic_migrate_sessions_on_network_change;
jrid36ada62016-02-06 02:42:08150 // If true, active QUIC sessions experiencing poor connectivity may be
151 // migrated onto a new network.
152 bool quic_migrate_sessions_early;
jri217455a12016-07-13 20:15:09153 // If true, allows migration of QUIC connections to a server-specified
154 // alternate server address.
155 bool quic_allow_server_migration;
xunjieli888c29922016-03-18 21:05:09156 // If true, bidirectional streams over QUIC will be disabled.
157 bool quic_disable_bidirectional_streams;
ckrasicda193a82016-07-09 00:39:36158 // If true, enable force HOL blocking. For measurement purposes.
159 bool quic_force_hol_blocking;
rtennetid073dd22016-08-04 01:58:33160 // If true, race cert verification with host resolution.
161 bool quic_race_cert_verification;
rchd6163f32017-01-30 23:50:38162 // If true, estimate the initial RTT for QUIC connections based on network.
163 bool quic_estimate_initial_rtt;
xunjieli888c29922016-03-18 21:05:09164
nharperb7441ef2016-01-25 23:54:14165 // Enable support for Token Binding.
166 bool enable_token_binding;
mmenkea7da6da2016-09-01 21:56:52167
168 // Enable HTTP/0.9 for HTTP/HTTPS on ports other than the default one for
169 // each protocol.
170 bool http_09_on_non_default_ports_enabled;
[email protected]cf4cae32014-05-27 00:39:10171 };
172
mmenke6ddfbea2017-05-31 21:48:41173 // Structure with pointers to the dependencies of the HttpNetworkSession.
174 // These objects must all outlive the HttpNetworkSession.
175 struct NET_EXPORT Context {
176 Context();
177 Context(const Context& other);
178 ~Context();
179
180 ClientSocketFactory* client_socket_factory;
181 HostResolver* host_resolver;
182 CertVerifier* cert_verifier;
183 ChannelIDService* channel_id_service;
184 TransportSecurityState* transport_security_state;
185 CTVerifier* cert_transparency_verifier;
186 CTPolicyEnforcer* ct_policy_enforcer;
187 ProxyService* proxy_service;
188 SSLConfigService* ssl_config_service;
189 HttpAuthHandlerFactory* http_auth_handler_factory;
190 HttpServerProperties* http_server_properties;
191 NetLog* net_log;
192 SocketPerformanceWatcherFactory* socket_performance_watcher_factory;
tbansal16196a1e2017-06-09 01:50:09193 NetworkQualityProvider* network_quality_provider;
mmenke6ddfbea2017-05-31 21:48:41194
195 // Source of time for QUIC connections.
196 QuicClock* quic_clock;
197 // Source of entropy for QUIC connections.
198 QuicRandom* quic_random;
199 // Optional factory to use for creating QuicCryptoClientStreams.
200 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
201
202 ProxyDelegate* proxy_delegate;
203 };
204
[email protected]cf4cae32014-05-27 00:39:10205 enum SocketPoolType {
206 NORMAL_SOCKET_POOL,
207 WEBSOCKET_SOCKET_POOL,
208 NUM_SOCKET_POOL_TYPES
209 };
210
mmenke6ddfbea2017-05-31 21:48:41211 HttpNetworkSession(const Params& params, const Context& context);
hajimehoshi8156e7c2016-09-29 06:17:52212 ~HttpNetworkSession() override;
[email protected]cf4cae32014-05-27 00:39:10213
214 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
215 SSLClientAuthCache* ssl_client_auth_cache() {
216 return &ssl_client_auth_cache_;
217 }
218
avifceb32f62016-10-07 16:30:52219 void AddResponseDrainer(std::unique_ptr<HttpResponseBodyDrainer> drainer);
[email protected]cf4cae32014-05-27 00:39:10220
avifceb32f62016-10-07 16:30:52221 // Removes the drainer from the session. Does not dispose of it.
[email protected]cf4cae32014-05-27 00:39:10222 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
223
224 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
225 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
226 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
227 SocketPoolType pool_type,
228 const HostPortPair& socks_proxy);
229 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
230 SocketPoolType pool_type,
231 const HostPortPair& http_proxy);
232 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
233 SocketPoolType pool_type,
234 const HostPortPair& proxy_server);
235
236 CertVerifier* cert_verifier() { return cert_verifier_; }
237 ProxyService* proxy_service() { return proxy_service_; }
238 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
239 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
240 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
241 HttpAuthHandlerFactory* http_auth_handler_factory() {
242 return http_auth_handler_factory_;
243 }
bnc525e175a2016-06-20 12:36:40244 HttpServerProperties* http_server_properties() {
[email protected]cf4cae32014-05-27 00:39:10245 return http_server_properties_;
246 }
247 HttpStreamFactory* http_stream_factory() {
248 return http_stream_factory_.get();
249 }
250 HttpStreamFactory* http_stream_factory_for_websocket() {
251 return http_stream_factory_for_websocket_.get();
252 }
rdsmith1d343be52016-10-21 20:37:50253 NetworkThrottleManager* throttler() {
254 return network_stream_throttler_.get();
255 }
[email protected]cf4cae32014-05-27 00:39:10256 NetLog* net_log() {
257 return net_log_;
258 }
[email protected]cf4cae32014-05-27 00:39:10259
payal.pandey62a400292015-05-28 09:29:54260 // Creates a Value summary of the state of the socket pools.
danakj1fd259a02016-04-16 03:17:09261 std::unique_ptr<base::Value> SocketPoolInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10262
payal.pandey91cb2312015-05-27 07:41:51263 // Creates a Value summary of the state of the SPDY sessions.
danakj1fd259a02016-04-16 03:17:09264 std::unique_ptr<base::Value> SpdySessionPoolInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10265
266 // Creates a Value summary of the state of the QUIC sessions and
payal.pandeya18956a2015-05-27 05:57:55267 // configuration.
danakj1fd259a02016-04-16 03:17:09268 std::unique_ptr<base::Value> QuicInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10269
270 void CloseAllConnections();
271 void CloseIdleConnections();
272
273 // Returns the original Params used to construct this session.
274 const Params& params() const { return params_; }
mmenke6ddfbea2017-05-31 21:48:41275 // Returns the original Context used to construct this session.
276 const Context& context() const { return context_; }
[email protected]cf4cae32014-05-27 00:39:10277
bnc3472afd2016-11-17 15:27:21278 bool IsProtocolEnabled(NextProto protocol) const;
[email protected]cf4cae32014-05-27 00:39:10279
zhongyiaf257542016-12-19 03:36:01280 void SetServerPushDelegate(std::unique_ptr<ServerPushDelegate> push_delegate);
281
bnc1f295372015-10-21 23:24:22282 // Populates |*alpn_protos| with protocols to be used with ALPN.
283 void GetAlpnProtos(NextProtoVector* alpn_protos) const;
284
nharper8cdb0fb2016-04-22 21:34:59285 // Populates |server_config| and |proxy_config| based on this session and
286 // |request|.
287 void GetSSLConfig(const HttpRequestInfo& request,
288 SSLConfig* server_config,
289 SSLConfig* proxy_config) const;
290
xunjieli9f8c5fb52016-12-07 22:59:33291 // Dumps memory allocation stats. |parent_dump_absolute_name| is the name
292 // used by the parent MemoryAllocatorDump in the memory dump hierarchy.
293 void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd,
294 const std::string& parent_absolute_name) const;
295
pmarko6ab8be242017-01-11 11:02:55296 // Evaluates if QUIC is enabled for new streams.
297 bool IsQuicEnabled() const;
298
299 // Disable QUIC for new streams.
300 void DisableQuic();
301
[email protected]cf4cae32014-05-27 00:39:10302 private:
[email protected]cf4cae32014-05-27 00:39:10303 friend class HttpNetworkSessionPeer;
304
[email protected]cf4cae32014-05-27 00:39:10305 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
306
maksim.sisov0adf8592016-07-15 06:25:56307 // Flush sockets on low memory notifications callback.
308 void OnMemoryPressure(
309 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
310
hajimehoshi8156e7c2016-09-29 06:17:52311 // base::MemoryCoordinatorClient implementation:
bashi56b23f302017-02-09 01:24:57312 void OnPurgeMemory() override;
hajimehoshi8156e7c2016-09-29 06:17:52313
[email protected]cf4cae32014-05-27 00:39:10314 NetLog* const net_log_;
bnc525e175a2016-06-20 12:36:40315 HttpServerProperties* const http_server_properties_;
[email protected]cf4cae32014-05-27 00:39:10316 CertVerifier* const cert_verifier_;
317 HttpAuthHandlerFactory* const http_auth_handler_factory_;
318
319 // Not const since it's modified by HttpNetworkSessionPeer for testing.
320 ProxyService* proxy_service_;
321 const scoped_refptr<SSLConfigService> ssl_config_service_;
322
323 HttpAuthCache http_auth_cache_;
324 SSLClientAuthCache ssl_client_auth_cache_;
danakj1fd259a02016-04-16 03:17:09325 std::unique_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
326 std::unique_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
zhongyiaf257542016-12-19 03:36:01327 std::unique_ptr<ServerPushDelegate> push_delegate_;
[email protected]cf4cae32014-05-27 00:39:10328 QuicStreamFactory quic_stream_factory_;
329 SpdySessionPool spdy_session_pool_;
danakj1fd259a02016-04-16 03:17:09330 std::unique_ptr<HttpStreamFactory> http_stream_factory_;
331 std::unique_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
avifceb32f62016-10-07 16:30:52332 std::map<HttpResponseBodyDrainer*, std::unique_ptr<HttpResponseBodyDrainer>>
333 response_drainers_;
rdsmith1d343be52016-10-21 20:37:50334 std::unique_ptr<NetworkThrottleManager> network_stream_throttler_;
[email protected]cf4cae32014-05-27 00:39:10335
bnc0d23cf42014-12-11 14:09:46336 NextProtoVector next_protos_;
[email protected]cf4cae32014-05-27 00:39:10337
338 Params params_;
mmenke6ddfbea2017-05-31 21:48:41339 Context context_;
maksim.sisov0adf8592016-07-15 06:25:56340
341 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
gab47aa7da2017-06-02 16:09:43342
343 THREAD_CHECKER(thread_checker_);
[email protected]cf4cae32014-05-27 00:39:10344};
345
346} // namespace net
347
348#endif // NET_HTTP_HTTP_NETWORK_SESSION_H_