blob: 5b1ecf40d298e966d2dceea45a9b3f36d30283c7 [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
[email protected]cf4cae32014-05-27 00:39:1011#include <set>
12#include <string>
rch74da0e1a2016-01-14 02:49:3213#include <unordered_set>
[email protected]cf4cae32014-05-27 00:39:1014#include <vector>
15
[email protected]cf4cae32014-05-27 00:39:1016#include "base/memory/ref_counted.h"
17#include "base/memory/weak_ptr.h"
18#include "base/threading/non_thread_safe.h"
19#include "net/base/host_port_pair.h"
20#include "net/base/net_export.h"
21#include "net/dns/host_resolver.h"
22#include "net/http/http_auth_cache.h"
23#include "net/http/http_stream_factory.h"
24#include "net/quic/quic_stream_factory.h"
25#include "net/socket/next_proto.h"
26#include "net/spdy/spdy_session_pool.h"
27#include "net/ssl/ssl_client_auth_cache.h"
28
29namespace base {
30class Value;
31}
32
33namespace net {
34
estark6f9b3d82016-01-12 21:37:0535class CTPolicyEnforcer;
[email protected]cf4cae32014-05-27 00:39:1036class CertVerifier;
[email protected]6b8a3c742014-07-25 00:25:3537class ChannelIDService;
[email protected]cf4cae32014-05-27 00:39:1038class ClientSocketFactory;
39class ClientSocketPoolManager;
40class CTVerifier;
41class HostResolver;
[email protected]cf4cae32014-05-27 00:39:1042class HttpAuthHandlerFactory;
43class HttpNetworkSessionPeer;
44class HttpProxyClientSocketPool;
45class HttpResponseBodyDrainer;
46class HttpServerProperties;
47class NetLog;
48class NetworkDelegate;
bengr39e406102014-09-10 23:04:4649class ProxyDelegate;
[email protected]cf4cae32014-05-27 00:39:1050class ProxyService;
51class QuicClock;
52class QuicCryptoClientStreamFactory;
53class QuicServerInfoFactory;
tbansalba8f4112015-09-03 21:57:1954class SocketPerformanceWatcherFactory;
[email protected]cf4cae32014-05-27 00:39:1055class SOCKSClientSocketPool;
56class SSLClientSocketPool;
57class SSLConfigService;
58class TransportClientSocketPool;
59class TransportSecurityState;
60
61// This class holds session objects used by HttpNetworkTransaction objects.
62class NET_EXPORT HttpNetworkSession
mmenkee65e7af2015-10-13 17:16:4263 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
[email protected]cf4cae32014-05-27 00:39:1064 public:
65 struct NET_EXPORT Params {
66 Params();
67 ~Params();
68
69 ClientSocketFactory* client_socket_factory;
70 HostResolver* host_resolver;
71 CertVerifier* cert_verifier;
estark6f9b3d82016-01-12 21:37:0572 CTPolicyEnforcer* ct_policy_enforcer;
[email protected]6b8a3c742014-07-25 00:25:3573 ChannelIDService* channel_id_service;
[email protected]cf4cae32014-05-27 00:39:1074 TransportSecurityState* transport_security_state;
75 CTVerifier* cert_transparency_verifier;
76 ProxyService* proxy_service;
[email protected]cf4cae32014-05-27 00:39:1077 SSLConfigService* ssl_config_service;
78 HttpAuthHandlerFactory* http_auth_handler_factory;
79 NetworkDelegate* network_delegate;
80 base::WeakPtr<HttpServerProperties> http_server_properties;
81 NetLog* net_log;
82 HostMappingRules* host_mapping_rules;
tbansalba8f4112015-09-03 21:57:1983 SocketPerformanceWatcherFactory* socket_performance_watcher_factory;
[email protected]cf4cae32014-05-27 00:39:1084 bool ignore_certificate_errors;
Avi Drissman13fc8932015-12-20 04:40:4685 uint16_t testing_fixed_http_port;
86 uint16_t testing_fixed_https_port;
jrif9b4bec2014-09-15 15:46:5487 bool enable_tcp_fast_open_for_ssl;
[email protected]cf4cae32014-05-27 00:39:1088
rchd502a302015-10-16 03:57:2189 // Compress SPDY headers.
[email protected]cf4cae32014-05-27 00:39:1090 bool enable_spdy_compression;
rchd502a302015-10-16 03:57:2191 // Use SPDY ping frames to test for connection health after idle.
[email protected]cf4cae32014-05-27 00:39:1092 bool enable_spdy_ping_based_connection_checking;
93 NextProto spdy_default_protocol;
94 // The protocols supported by NPN (next protocol negotiation) during the
95 // SSL handshake as well as by HTTP Alternate-Protocol.
96 // TODO(mmenke): This is currently empty by default, and alternate
97 // protocols are disabled. We should use some reasonable
98 // defaults.
99 NextProtoVector next_protos;
bnc8f0f3b62015-04-08 04:37:23100 size_t spdy_session_max_recv_window_size;
101 size_t spdy_stream_max_recv_window_size;
[email protected]cf4cae32014-05-27 00:39:10102 size_t spdy_initial_max_concurrent_streams;
rchd502a302015-10-16 03:57:21103 // Source of time for SPDY connections.
[email protected]cf4cae32014-05-27 00:39:10104 SpdySessionPool::TimeFunc time_func;
rchd502a302015-10-16 03:57:21105 // This SPDY proxy is allowed to push resources from origins that are
106 // different from those of their associated streams.
[email protected]cf4cae32014-05-27 00:39:10107 std::string trusted_spdy_proxy;
[email protected]cf4cae32014-05-27 00:39:10108 // URLs to exclude from forced SPDY.
109 std::set<HostPortPair> forced_spdy_exclusions;
rchd502a302015-10-16 03:57:21110 // Process Alt-Svc headers.
bnc55ff9da2015-08-19 18:42:35111 bool use_alternative_services;
rchd502a302015-10-16 03:57:21112 // Only honor alternative service entries which have a higher probability
113 // than this value.
bnc62891a52015-04-27 14:14:12114 double alternative_service_probability_threshold;
[email protected]cf4cae32014-05-27 00:39:10115
bnc65b99312015-10-29 01:05:36116 // Enables NPN support. Note that ALPN is always enabled.
117 bool enable_npn;
118
eustasfbec9132015-12-30 14:56:51119 // Enables Brotli Content-Encoding support.
120 bool enable_brotli;
121
rchd502a302015-10-16 03:57:21122 // Enables QUIC support.
[email protected]cf4cae32014-05-27 00:39:10123 bool enable_quic;
rchd502a302015-10-16 03:57:21124 // Enables QUIC for proxies.
tbansaled0aecc2015-02-20 03:44:18125 bool enable_quic_for_proxies;
rchd502a302015-10-16 03:57:21126 // Instruct QUIC to use consistent ephemeral ports when talking to
127 // the same server.
[email protected]cf4cae32014-05-27 00:39:10128 bool enable_quic_port_selection;
rchd502a302015-10-16 03:57:21129 // Disables QUIC's 0-RTT behavior.
jri2b966f22014-09-02 22:25:36130 bool quic_always_require_handshake_confirmation;
rchd502a302015-10-16 03:57:21131 // Disables QUIC connection pooling.
jri584002d12014-09-09 00:51:28132 bool quic_disable_connection_pooling;
rchd502a302015-10-16 03:57:21133 // If not zero, the task to load QUIC server configs from the disk cache
134 // will timeout after this value multiplied by the smoothed RTT for the
135 // server.
rtenneti2912825c2015-01-06 01:19:46136 float quic_load_server_info_timeout_srtt_multiplier;
rchd502a302015-10-16 03:57:21137 // Causes QUIC to race reading the server config from disk with
138 // sending an inchoate CHLO.
rtenneti4f809972015-02-11 19:38:34139 bool quic_enable_connection_racing;
rchd502a302015-10-16 03:57:21140 // Use non-blocking IO for UDP sockets.
qyearsley3257b7de2015-02-28 06:59:03141 bool quic_enable_non_blocking_io;
rchd502a302015-10-16 03:57:21142 // Disables using the disk cache to store QUIC server configs.
rtenneti34dffe752015-02-24 23:27:32143 bool quic_disable_disk_cache;
rchd502a302015-10-16 03:57:21144 // Prefer AES-GCM to ChaCha20 even if no hardware support is present.
rch9976b0c2015-06-10 21:27:23145 bool quic_prefer_aes;
rchd502a302015-10-16 03:57:21146 // Specifies the maximum number of connections with high packet loss in
147 // a row after which QUIC will be disabled.
rtenneti85dcfac22015-03-27 20:22:19148 int quic_max_number_of_lossy_connections;
rchd502a302015-10-16 03:57:21149 // Specifies packet loss rate in fraction after which a connection is
150 // closed and is considered as a lossy connection.
rtenneti85dcfac22015-03-27 20:22:19151 float quic_packet_loss_threshold;
rchd502a302015-10-16 03:57:21152 // Size in bytes of the QUIC DUP socket receive buffer.
rchc7433572015-02-27 18:16:51153 int quic_socket_receive_buffer_size;
rchd502a302015-10-16 03:57:21154 // Delay starting a TCP connection when QUIC believes it can speak
155 // 0-RTT to a server.
rtenneti8332ba52015-09-17 19:33:41156 bool quic_delay_tcp_race;
rchd502a302015-10-16 03:57:21157 // Store server configs in HttpServerProperties, instead of the disk cache.
rtenneticd2aaa15b2015-10-10 20:29:33158 bool quic_store_server_configs_in_properties;
rchd502a302015-10-16 03:57:21159 // If not empty, QUIC will be used for all connections to this origin.
[email protected]cf4cae32014-05-27 00:39:10160 HostPortPair origin_to_force_quic_on;
rchd502a302015-10-16 03:57:21161 // Source of time for QUIC connections. Will be owned by QuicStreamFactory.
162 QuicClock* quic_clock;
163 // Source of entropy for QUIC connections.
[email protected]cf4cae32014-05-27 00:39:10164 QuicRandom* quic_random;
rchd502a302015-10-16 03:57:21165 // Limit on the size of QUIC packets.
[email protected]cf4cae32014-05-27 00:39:10166 size_t quic_max_packet_length;
rchd502a302015-10-16 03:57:21167 // User agent description to send in the QUIC handshake.
[email protected]0c4017ca2014-06-06 03:30:45168 std::string quic_user_agent_id;
[email protected]cf4cae32014-05-27 00:39:10169 bool enable_user_alternate_protocol_ports;
rchd502a302015-10-16 03:57:21170 // Optional factory to use for creating QuicCryptoClientStreams.
[email protected]cf4cae32014-05-27 00:39:10171 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
rchd502a302015-10-16 03:57:21172 // Versions of QUIC which may be used.
[email protected]cf4cae32014-05-27 00:39:10173 QuicVersionVector quic_supported_versions;
ckrasic1e53b642015-07-08 22:39:35174 int quic_max_recent_disabled_reasons;
175 int quic_threshold_public_resets_post_handshake;
176 int quic_threshold_timeouts_streams_open;
jri8c44d692015-10-23 23:53:41177 // Set of QUIC tags to send in the handshake's connection options.
[email protected]488a0e252014-06-25 04:37:44178 QuicTagVector quic_connection_options;
jri8c44d692015-10-23 23:53:41179 // If true, all QUIC sessions are closed when any local IP address changes.
180 bool quic_close_sessions_on_ip_change;
rtenneti41c09992015-11-30 18:24:01181 // Specifes QUIC idle connection state lifetime.
182 int quic_idle_connection_timeout_seconds;
rtennetid2e74caa2015-12-09 00:51:57183 // If true, disable preconnections if QUIC can do 0RTT.
184 bool quic_disable_preconnect_if_0rtt;
rch74da0e1a2016-01-14 02:49:32185 // List of hosts for which QUIC is explicitly whitelisted.
186 std::unordered_set<std::string> quic_host_whitelist;
187
bengr39e406102014-09-10 23:04:46188 ProxyDelegate* proxy_delegate;
[email protected]cf4cae32014-05-27 00:39:10189 };
190
191 enum SocketPoolType {
192 NORMAL_SOCKET_POOL,
193 WEBSOCKET_SOCKET_POOL,
194 NUM_SOCKET_POOL_TYPES
195 };
196
197 explicit HttpNetworkSession(const Params& params);
mmenkee65e7af2015-10-13 17:16:42198 ~HttpNetworkSession();
[email protected]cf4cae32014-05-27 00:39:10199
200 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
201 SSLClientAuthCache* ssl_client_auth_cache() {
202 return &ssl_client_auth_cache_;
203 }
204
205 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
206
207 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
208
209 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
210 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
211 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
212 SocketPoolType pool_type,
213 const HostPortPair& socks_proxy);
214 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
215 SocketPoolType pool_type,
216 const HostPortPair& http_proxy);
217 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
218 SocketPoolType pool_type,
219 const HostPortPair& proxy_server);
220
221 CertVerifier* cert_verifier() { return cert_verifier_; }
222 ProxyService* proxy_service() { return proxy_service_; }
223 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
224 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
225 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
226 HttpAuthHandlerFactory* http_auth_handler_factory() {
227 return http_auth_handler_factory_;
228 }
229 NetworkDelegate* network_delegate() {
230 return network_delegate_;
231 }
232 base::WeakPtr<HttpServerProperties> http_server_properties() {
233 return http_server_properties_;
234 }
235 HttpStreamFactory* http_stream_factory() {
236 return http_stream_factory_.get();
237 }
238 HttpStreamFactory* http_stream_factory_for_websocket() {
239 return http_stream_factory_for_websocket_.get();
240 }
241 NetLog* net_log() {
242 return net_log_;
243 }
[email protected]cf4cae32014-05-27 00:39:10244
payal.pandey62a400292015-05-28 09:29:54245 // Creates a Value summary of the state of the socket pools.
246 scoped_ptr<base::Value> SocketPoolInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10247
payal.pandey91cb2312015-05-27 07:41:51248 // Creates a Value summary of the state of the SPDY sessions.
249 scoped_ptr<base::Value> SpdySessionPoolInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10250
251 // Creates a Value summary of the state of the QUIC sessions and
payal.pandeya18956a2015-05-27 05:57:55252 // configuration.
253 scoped_ptr<base::Value> QuicInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10254
255 void CloseAllConnections();
256 void CloseIdleConnections();
257
258 // Returns the original Params used to construct this session.
259 const Params& params() const { return params_; }
260
261 bool IsProtocolEnabled(AlternateProtocol protocol) const;
262
bnc1f295372015-10-21 23:24:22263 // Populates |*alpn_protos| with protocols to be used with ALPN.
264 void GetAlpnProtos(NextProtoVector* alpn_protos) const;
265
266 // Populates |*npn_protos| with protocols to be used with NPN.
267 void GetNpnProtos(NextProtoVector* npn_protos) const;
[email protected]cf4cae32014-05-27 00:39:10268
269 // Convenience function for searching through |params_| for
270 // |forced_spdy_exclusions|.
271 bool HasSpdyExclusion(HostPortPair host_port_pair) const;
272
273 private:
[email protected]cf4cae32014-05-27 00:39:10274 friend class HttpNetworkSessionPeer;
275
[email protected]cf4cae32014-05-27 00:39:10276 ClientSocketPoolManager* GetSocketPoolManager(SocketPoolType pool_type);
277
278 NetLog* const net_log_;
279 NetworkDelegate* const network_delegate_;
280 const base::WeakPtr<HttpServerProperties> http_server_properties_;
281 CertVerifier* const cert_verifier_;
282 HttpAuthHandlerFactory* const http_auth_handler_factory_;
283
284 // Not const since it's modified by HttpNetworkSessionPeer for testing.
285 ProxyService* proxy_service_;
286 const scoped_refptr<SSLConfigService> ssl_config_service_;
287
288 HttpAuthCache http_auth_cache_;
289 SSLClientAuthCache ssl_client_auth_cache_;
290 scoped_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
291 scoped_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
292 QuicStreamFactory quic_stream_factory_;
293 SpdySessionPool spdy_session_pool_;
294 scoped_ptr<HttpStreamFactory> http_stream_factory_;
295 scoped_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
296 std::set<HttpResponseBodyDrainer*> response_drainers_;
297
bnc0d23cf42014-12-11 14:09:46298 NextProtoVector next_protos_;
[email protected]cf4cae32014-05-27 00:39:10299 bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
300
301 Params params_;
302};
303
304} // namespace net
305
306#endif // NET_HTTP_HTTP_NETWORK_SESSION_H_