blob: 1270ce52d1b7780c7859ebe4ebf988bfd5040f4d [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;
bengr39e406102014-09-10 23:04:4648class ProxyDelegate;
[email protected]cf4cae32014-05-27 00:39:1049class ProxyService;
50class QuicClock;
51class QuicCryptoClientStreamFactory;
52class QuicServerInfoFactory;
tbansalba8f4112015-09-03 21:57:1953class SocketPerformanceWatcherFactory;
[email protected]cf4cae32014-05-27 00:39:1054class SOCKSClientSocketPool;
55class SSLClientSocketPool;
56class SSLConfigService;
57class TransportClientSocketPool;
58class TransportSecurityState;
59
60// This class holds session objects used by HttpNetworkTransaction objects.
61class NET_EXPORT HttpNetworkSession
mmenkee65e7af2015-10-13 17:16:4262 : NON_EXPORTED_BASE(public base::NonThreadSafe) {
[email protected]cf4cae32014-05-27 00:39:1063 public:
64 struct NET_EXPORT Params {
65 Params();
vmpstracd23b72016-02-26 21:08:5566 Params(const Params& other);
[email protected]cf4cae32014-05-27 00:39:1067 ~Params();
68
69 ClientSocketFactory* client_socket_factory;
70 HostResolver* host_resolver;
71 CertVerifier* cert_verifier;
[email protected]6b8a3c742014-07-25 00:25:3572 ChannelIDService* channel_id_service;
[email protected]cf4cae32014-05-27 00:39:1073 TransportSecurityState* transport_security_state;
74 CTVerifier* cert_transparency_verifier;
rsleevid6de8302016-06-21 01:33:2075 CTPolicyEnforcer* ct_policy_enforcer;
[email protected]cf4cae32014-05-27 00:39:1076 ProxyService* proxy_service;
[email protected]cf4cae32014-05-27 00:39:1077 SSLConfigService* ssl_config_service;
78 HttpAuthHandlerFactory* http_auth_handler_factory;
bnc525e175a2016-06-20 12:36:4079 HttpServerProperties* http_server_properties;
[email protected]cf4cae32014-05-27 00:39:1080 NetLog* net_log;
81 HostMappingRules* host_mapping_rules;
tbansalba8f4112015-09-03 21:57:1982 SocketPerformanceWatcherFactory* socket_performance_watcher_factory;
[email protected]cf4cae32014-05-27 00:39:1083 bool ignore_certificate_errors;
Avi Drissman13fc8932015-12-20 04:40:4684 uint16_t testing_fixed_http_port;
85 uint16_t testing_fixed_https_port;
jrif9b4bec2014-09-15 15:46:5486 bool enable_tcp_fast_open_for_ssl;
[email protected]cf4cae32014-05-27 00:39:1087
rchd502a302015-10-16 03:57:2188 // Use SPDY ping frames to test for connection health after idle.
[email protected]cf4cae32014-05-27 00:39:1089 bool enable_spdy_ping_based_connection_checking;
90 NextProto spdy_default_protocol;
bnc3f0118e2016-02-02 15:42:2291 bool enable_spdy31;
92 bool enable_http2;
bnc8f0f3b62015-04-08 04:37:2393 size_t spdy_session_max_recv_window_size;
94 size_t spdy_stream_max_recv_window_size;
rchd502a302015-10-16 03:57:2195 // Source of time for SPDY connections.
[email protected]cf4cae32014-05-27 00:39:1096 SpdySessionPool::TimeFunc time_func;
bncf33fb31b2016-01-29 15:22:2697 // Whether to enable Alt-Svc entries with hostname different than that of
98 // the origin.
99 bool enable_alternative_service_with_different_host;
bnce3dd56f2016-06-01 10:37:11100 // Only set for tests.
101 // TODO(bnc) https://crbug.com/615497:
102 // Adapt tests to https requests, remove this member.
103 bool enable_alternative_service_for_insecure_origins;
[email protected]cf4cae32014-05-27 00:39:10104
bnc65b99312015-10-29 01:05:36105 // Enables NPN support. Note that ALPN is always enabled.
106 bool enable_npn;
107
rdsmith2e54d1f2016-03-21 19:48:17108 // Enable setting of HTTP/2 dependencies based on priority.
109 bool enable_priority_dependencies;
110
rchd502a302015-10-16 03:57:21111 // Enables QUIC support.
[email protected]cf4cae32014-05-27 00:39:10112 bool enable_quic;
zhongyi75527dd2016-01-21 22:26:43113 // Disable QUIC if a connection times out with open streams.
114 bool disable_quic_on_timeout_with_open_streams;
rchd502a302015-10-16 03:57:21115 // Instruct QUIC to use consistent ephemeral ports when talking to
116 // the same server.
[email protected]cf4cae32014-05-27 00:39:10117 bool enable_quic_port_selection;
rchd502a302015-10-16 03:57:21118 // Disables QUIC's 0-RTT behavior.
jri2b966f22014-09-02 22:25:36119 bool quic_always_require_handshake_confirmation;
rchd502a302015-10-16 03:57:21120 // Disables QUIC connection pooling.
jri584002d12014-09-09 00:51:28121 bool quic_disable_connection_pooling;
rchd502a302015-10-16 03:57:21122 // If not zero, the task to load QUIC server configs from the disk cache
123 // will timeout after this value multiplied by the smoothed RTT for the
124 // server.
rtenneti2912825c2015-01-06 01:19:46125 float quic_load_server_info_timeout_srtt_multiplier;
rchd502a302015-10-16 03:57:21126 // Causes QUIC to race reading the server config from disk with
127 // sending an inchoate CHLO.
rtenneti4f809972015-02-11 19:38:34128 bool quic_enable_connection_racing;
rchd502a302015-10-16 03:57:21129 // Use non-blocking IO for UDP sockets.
qyearsley3257b7de2015-02-28 06:59:03130 bool quic_enable_non_blocking_io;
rchd502a302015-10-16 03:57:21131 // Disables using the disk cache to store QUIC server configs.
rtenneti34dffe752015-02-24 23:27:32132 bool quic_disable_disk_cache;
rchd502a302015-10-16 03:57:21133 // Prefer AES-GCM to ChaCha20 even if no hardware support is present.
rch9976b0c2015-06-10 21:27:23134 bool quic_prefer_aes;
rchd502a302015-10-16 03:57:21135 // Specifies the maximum number of connections with high packet loss in
136 // a row after which QUIC will be disabled.
rtenneti85dcfac22015-03-27 20:22:19137 int quic_max_number_of_lossy_connections;
rchd502a302015-10-16 03:57:21138 // Specifies packet loss rate in fraction after which a connection is
139 // closed and is considered as a lossy connection.
rtenneti85dcfac22015-03-27 20:22:19140 float quic_packet_loss_threshold;
rchd502a302015-10-16 03:57:21141 // Size in bytes of the QUIC DUP socket receive buffer.
rchc7433572015-02-27 18:16:51142 int quic_socket_receive_buffer_size;
rtennetib8e80fb2016-05-16 00:12:09143 // Delay starting a TCP connection when QUIC believes it can speak
144 // 0-RTT to a server.
145 bool quic_delay_tcp_race;
rtenneti6971c172016-01-15 20:12:10146 // Maximum number of server configs that are to be stored in
147 // HttpServerProperties, instead of the disk cache.
148 size_t quic_max_server_configs_stored_in_properties;
rtenneti8a2f4632016-03-21 20:26:57149 // If not empty, QUIC will be used for all connections to the set of
150 // origins in |origins_to_force_quic_on|.
151 std::set<HostPortPair> origins_to_force_quic_on;
rchd502a302015-10-16 03:57:21152 // Source of time for QUIC connections. Will be owned by QuicStreamFactory.
153 QuicClock* quic_clock;
154 // Source of entropy for QUIC connections.
[email protected]cf4cae32014-05-27 00:39:10155 QuicRandom* quic_random;
rchd502a302015-10-16 03:57:21156 // Limit on the size of QUIC packets.
[email protected]cf4cae32014-05-27 00:39:10157 size_t quic_max_packet_length;
rchd502a302015-10-16 03:57:21158 // User agent description to send in the QUIC handshake.
[email protected]0c4017ca2014-06-06 03:30:45159 std::string quic_user_agent_id;
[email protected]cf4cae32014-05-27 00:39:10160 bool enable_user_alternate_protocol_ports;
rchd502a302015-10-16 03:57:21161 // Optional factory to use for creating QuicCryptoClientStreams.
[email protected]cf4cae32014-05-27 00:39:10162 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory;
rchd502a302015-10-16 03:57:21163 // Versions of QUIC which may be used.
[email protected]cf4cae32014-05-27 00:39:10164 QuicVersionVector quic_supported_versions;
ckrasic1e53b642015-07-08 22:39:35165 int quic_max_recent_disabled_reasons;
166 int quic_threshold_public_resets_post_handshake;
167 int quic_threshold_timeouts_streams_open;
jri8c44d692015-10-23 23:53:41168 // Set of QUIC tags to send in the handshake's connection options.
[email protected]488a0e252014-06-25 04:37:44169 QuicTagVector quic_connection_options;
jri8c44d692015-10-23 23:53:41170 // If true, all QUIC sessions are closed when any local IP address changes.
171 bool quic_close_sessions_on_ip_change;
rtenneti41c09992015-11-30 18:24:01172 // Specifes QUIC idle connection state lifetime.
173 int quic_idle_connection_timeout_seconds;
rtennetid2e74caa2015-12-09 00:51:57174 // If true, disable preconnections if QUIC can do 0RTT.
175 bool quic_disable_preconnect_if_0rtt;
rch74da0e1a2016-01-14 02:49:32176 // List of hosts for which QUIC is explicitly whitelisted.
177 std::unordered_set<std::string> quic_host_whitelist;
jrid36ada62016-02-06 02:42:08178 // If true, active QUIC sessions may be migrated onto a new network when
179 // the platform indicates that the default network is changing.
jri7e636642016-01-14 06:57:08180 bool quic_migrate_sessions_on_network_change;
jrid36ada62016-02-06 02:42:08181 // If true, active QUIC sessions experiencing poor connectivity may be
182 // migrated onto a new network.
183 bool quic_migrate_sessions_early;
xunjieli888c29922016-03-18 21:05:09184 // If true, bidirectional streams over QUIC will be disabled.
185 bool quic_disable_bidirectional_streams;
186
bengr39e406102014-09-10 23:04:46187 ProxyDelegate* proxy_delegate;
nharperb7441ef2016-01-25 23:54:14188 // Enable support for Token Binding.
189 bool enable_token_binding;
[email protected]cf4cae32014-05-27 00:39:10190 };
191
192 enum SocketPoolType {
193 NORMAL_SOCKET_POOL,
194 WEBSOCKET_SOCKET_POOL,
195 NUM_SOCKET_POOL_TYPES
196 };
197
198 explicit HttpNetworkSession(const Params& params);
mmenkee65e7af2015-10-13 17:16:42199 ~HttpNetworkSession();
[email protected]cf4cae32014-05-27 00:39:10200
201 HttpAuthCache* http_auth_cache() { return &http_auth_cache_; }
202 SSLClientAuthCache* ssl_client_auth_cache() {
203 return &ssl_client_auth_cache_;
204 }
205
206 void AddResponseDrainer(HttpResponseBodyDrainer* drainer);
207
208 void RemoveResponseDrainer(HttpResponseBodyDrainer* drainer);
209
210 TransportClientSocketPool* GetTransportSocketPool(SocketPoolType pool_type);
211 SSLClientSocketPool* GetSSLSocketPool(SocketPoolType pool_type);
212 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
213 SocketPoolType pool_type,
214 const HostPortPair& socks_proxy);
215 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
216 SocketPoolType pool_type,
217 const HostPortPair& http_proxy);
218 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
219 SocketPoolType pool_type,
220 const HostPortPair& proxy_server);
221
222 CertVerifier* cert_verifier() { return cert_verifier_; }
223 ProxyService* proxy_service() { return proxy_service_; }
224 SSLConfigService* ssl_config_service() { return ssl_config_service_.get(); }
225 SpdySessionPool* spdy_session_pool() { return &spdy_session_pool_; }
226 QuicStreamFactory* quic_stream_factory() { return &quic_stream_factory_; }
227 HttpAuthHandlerFactory* http_auth_handler_factory() {
228 return http_auth_handler_factory_;
229 }
bnc525e175a2016-06-20 12:36:40230 HttpServerProperties* http_server_properties() {
[email protected]cf4cae32014-05-27 00:39:10231 return http_server_properties_;
232 }
233 HttpStreamFactory* http_stream_factory() {
234 return http_stream_factory_.get();
235 }
236 HttpStreamFactory* http_stream_factory_for_websocket() {
237 return http_stream_factory_for_websocket_.get();
238 }
239 NetLog* net_log() {
240 return net_log_;
241 }
[email protected]cf4cae32014-05-27 00:39:10242
payal.pandey62a400292015-05-28 09:29:54243 // Creates a Value summary of the state of the socket pools.
danakj1fd259a02016-04-16 03:17:09244 std::unique_ptr<base::Value> SocketPoolInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10245
payal.pandey91cb2312015-05-27 07:41:51246 // Creates a Value summary of the state of the SPDY sessions.
danakj1fd259a02016-04-16 03:17:09247 std::unique_ptr<base::Value> SpdySessionPoolInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10248
249 // Creates a Value summary of the state of the QUIC sessions and
payal.pandeya18956a2015-05-27 05:57:55250 // configuration.
danakj1fd259a02016-04-16 03:17:09251 std::unique_ptr<base::Value> QuicInfoToValue() const;
[email protected]cf4cae32014-05-27 00:39:10252
253 void CloseAllConnections();
254 void CloseIdleConnections();
255
256 // Returns the original Params used to construct this session.
257 const Params& params() const { return params_; }
258
259 bool IsProtocolEnabled(AlternateProtocol protocol) const;
260
bnc1f295372015-10-21 23:24:22261 // Populates |*alpn_protos| with protocols to be used with ALPN.
262 void GetAlpnProtos(NextProtoVector* alpn_protos) const;
263
264 // Populates |*npn_protos| with protocols to be used with NPN.
265 void GetNpnProtos(NextProtoVector* npn_protos) const;
[email protected]cf4cae32014-05-27 00:39:10266
nharper8cdb0fb2016-04-22 21:34:59267 // Populates |server_config| and |proxy_config| based on this session and
268 // |request|.
269 void GetSSLConfig(const HttpRequestInfo& request,
270 SSLConfig* server_config,
271 SSLConfig* proxy_config) const;
272
[email protected]cf4cae32014-05-27 00:39:10273 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_;
bnc525e175a2016-06-20 12:36:40279 HttpServerProperties* const http_server_properties_;
[email protected]cf4cae32014-05-27 00:39:10280 CertVerifier* const cert_verifier_;
281 HttpAuthHandlerFactory* const http_auth_handler_factory_;
282
283 // Not const since it's modified by HttpNetworkSessionPeer for testing.
284 ProxyService* proxy_service_;
285 const scoped_refptr<SSLConfigService> ssl_config_service_;
286
287 HttpAuthCache http_auth_cache_;
288 SSLClientAuthCache ssl_client_auth_cache_;
danakj1fd259a02016-04-16 03:17:09289 std::unique_ptr<ClientSocketPoolManager> normal_socket_pool_manager_;
290 std::unique_ptr<ClientSocketPoolManager> websocket_socket_pool_manager_;
[email protected]cf4cae32014-05-27 00:39:10291 QuicStreamFactory quic_stream_factory_;
292 SpdySessionPool spdy_session_pool_;
danakj1fd259a02016-04-16 03:17:09293 std::unique_ptr<HttpStreamFactory> http_stream_factory_;
294 std::unique_ptr<HttpStreamFactory> http_stream_factory_for_websocket_;
[email protected]cf4cae32014-05-27 00:39:10295 std::set<HttpResponseBodyDrainer*> response_drainers_;
296
bnc0d23cf42014-12-11 14:09:46297 NextProtoVector next_protos_;
[email protected]cf4cae32014-05-27 00:39:10298 bool enabled_protocols_[NUM_VALID_ALTERNATE_PROTOCOLS];
299
300 Params params_;
301};
302
303} // namespace net
304
305#endif // NET_HTTP_HTTP_NETWORK_SESSION_H_