blob: ea6ba22b26f249f8b953de9c982bc260243c123e [file] [log] [blame]
[email protected]94de3e02014-06-17 00:09:511// Copyright 2014 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 COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_
6#define COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_
7
dchengfe3745e6242016-04-21 23:49:588#include <memory>
[email protected]94de3e02014-06-17 00:09:519#include <string>
Donna Wu7ea51c22017-06-20 08:34:5210#include <vector>
[email protected]94de3e02014-06-17 00:09:5111
mefc71361c2014-09-16 14:48:5612#include "base/macros.h"
xunjielida7f77022016-03-28 16:36:3613#include "base/memory/ref_counted.h"
tbansale11aa362017-07-04 15:59:3614#include "base/optional.h"
kapishnikovdf5ccab2015-12-03 18:38:5015#include "base/time/time.h"
mgershcc6ae892017-06-20 22:33:5316#include "base/values.h"
pauljensen9041eb3c2015-12-09 12:29:0117#include "net/base/hash_value.h"
lilyhoughton14e2a1f12017-01-11 14:50:2718#include "net/cert/cert_verifier.h"
mmenkecf3cb2a2017-07-07 20:48:4419#include "net/http/http_network_session.h"
tbansale11aa362017-07-04 15:59:3620#include "net/nqe/effective_connection_type.h"
[email protected]94de3e02014-06-17 00:09:5121
22namespace net {
xunjieli013145f2015-10-20 23:20:1123class CertVerifier;
Victor Vasilieva1e66d72019-12-05 17:55:3824struct QuicParams;
[email protected]94de3e02014-06-17 00:09:5125class URLRequestContextBuilder;
26} // namespace net
27
28namespace cronet {
29
30// Common configuration parameters used by Cronet to configure
pauljensen9041eb3c2015-12-09 12:29:0131// URLRequestContext.
mgershcc6ae892017-06-20 22:33:5332// TODO(mgersh): This shouldn't be a struct, and experimental option parsing
33// should be kept more separate from applying the configuration.
[email protected]94de3e02014-06-17 00:09:5134struct URLRequestContextConfig {
pauljensen9041eb3c2015-12-09 12:29:0135 // Type of HTTP cache.
kapishnikovaa8f338c2016-10-28 16:17:3236 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net.impl
pauljensen9041eb3c2015-12-09 12:29:0137 enum HttpCacheType {
38 // No HTTP cache.
39 DISABLED,
40 // HTTP cache persisted to disk.
41 DISK,
42 // HTTP cache kept in memory.
43 MEMORY,
44 };
45
mefc71361c2014-09-16 14:48:5646 // App-provided hint that server supports QUIC.
47 struct QuicHint {
pauljensen9041eb3c2015-12-09 12:29:0148 QuicHint(const std::string& host, int port, int alternate_port);
mefc71361c2014-09-16 14:48:5649 ~QuicHint();
50
mefc71361c2014-09-16 14:48:5651 // Host name of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0152 const std::string host;
mefc71361c2014-09-16 14:48:5653 // Port of the server that supports QUIC.
pauljensen9041eb3c2015-12-09 12:29:0154 const int port;
mefc71361c2014-09-16 14:48:5655 // Alternate protocol port.
pauljensen9041eb3c2015-12-09 12:29:0156 const int alternate_port;
mefc71361c2014-09-16 14:48:5657
58 private:
59 DISALLOW_COPY_AND_ASSIGN(QuicHint);
60 };
61
kapishnikovdf5ccab2015-12-03 18:38:5062 // Public-Key-Pinning configuration structure.
63 struct Pkp {
pauljensen9041eb3c2015-12-09 12:29:0164 Pkp(const std::string& host,
65 bool include_subdomains,
66 const base::Time& expiration_date);
kapishnikovdf5ccab2015-12-03 18:38:5067 ~Pkp();
68
kapishnikovdf5ccab2015-12-03 18:38:5069 // Host name.
pauljensen9041eb3c2015-12-09 12:29:0170 const std::string host;
kapishnikovdf5ccab2015-12-03 18:38:5071 // Pin hashes (currently SHA256 only).
pauljensen9041eb3c2015-12-09 12:29:0172 net::HashValueVector pin_hashes;
kapishnikovdf5ccab2015-12-03 18:38:5073 // Indicates whether the pinning should apply to the pinned host subdomains.
pauljensen9041eb3c2015-12-09 12:29:0174 const bool include_subdomains;
kapishnikovdf5ccab2015-12-03 18:38:5075 // Expiration date for the pins.
pauljensen9041eb3c2015-12-09 12:29:0176 const base::Time expiration_date;
kapishnikovdf5ccab2015-12-03 18:38:5077
78 private:
79 DISALLOW_COPY_AND_ASSIGN(Pkp);
80 };
81
Douglas Creagera220947e2018-08-23 20:08:5382 // Simulated headers, used to preconfigure the Reporting API and Network Error
83 // Logging before receiving those actual configuration headers from the
84 // origins.
85 struct PreloadedNelAndReportingHeader {
86 PreloadedNelAndReportingHeader(const url::Origin& origin,
87 std::string value);
88 ~PreloadedNelAndReportingHeader();
89
90 // Origin that is "sending" this header.
91 const url::Origin origin;
92
93 // Value of the header that is "sent".
94 const std::string value;
95 };
96
pauljensen9041eb3c2015-12-09 12:29:0197 URLRequestContextConfig(
98 // Enable QUIC.
99 bool enable_quic,
mefc5da5712016-02-09 20:14:23100 // QUIC User Agent ID.
101 const std::string& quic_user_agent_id,
pauljensen9041eb3c2015-12-09 12:29:01102 // Enable SPDY.
103 bool enable_spdy,
xunjieli186d2bf2017-04-18 13:45:47104 // Enable Brotli.
105 bool enable_brotli,
pauljensen9041eb3c2015-12-09 12:29:01106 // Type of http cache.
107 HttpCacheType http_cache,
108 // Max size of http cache in bytes.
109 int http_cache_max_size,
110 // Disable caching for HTTP responses. Other information may be stored in
111 // the cache.
112 bool load_disable_cache,
113 // Storage path for http cache and cookie storage.
114 const std::string& storage_path,
Misha Efimovd4ab38302018-01-30 23:56:42115 // Accept-Language request header field.
116 const std::string& accept_language,
pauljensen9041eb3c2015-12-09 12:29:01117 // User-Agent request header field.
118 const std::string& user_agent,
119 // JSON encoded experimental options.
120 const std::string& experimental_options,
pauljensen9041eb3c2015-12-09 12:29:01121 // MockCertVerifier to use for testing purposes.
tbansal7018e2a2016-06-25 00:40:39122 std::unique_ptr<net::CertVerifier> mock_cert_verifier,
123 // Enable network quality estimator.
kapishnikov385aa422016-07-01 20:53:02124 bool enable_network_quality_estimator,
125 // Enable bypassing of public key pinning for local trust anchors
Paul Jensen6a1ea3a2018-08-24 14:46:41126 bool bypass_public_key_pinning_for_local_trust_anchors,
127 // Optional network thread priority.
128 // On Android, corresponds to android.os.Process.setThreadPriority()
129 // values. On iOS, corresponds to NSThread::setThreadPriority values. Do
130 // not specify for other targets.
131 base::Optional<double> network_thread_priority);
[email protected]94de3e02014-06-17 00:09:51132 ~URLRequestContextConfig();
133
xunjielid67295e2017-03-16 21:05:41134 // Configures |context_builder| based on |this|.
[email protected]94de3e02014-06-17 00:09:51135 void ConfigureURLRequestContextBuilder(
Matt Muellerde5dadf2019-11-27 20:11:58136 net::URLRequestContextBuilder* context_builder);
[email protected]94de3e02014-06-17 00:09:51137
[email protected]94de3e02014-06-17 00:09:51138 // Enable QUIC.
pauljensen9041eb3c2015-12-09 12:29:01139 const bool enable_quic;
mefc5da5712016-02-09 20:14:23140 // QUIC User Agent ID.
141 const std::string quic_user_agent_id;
[email protected]94de3e02014-06-17 00:09:51142 // Enable SPDY.
pauljensen9041eb3c2015-12-09 12:29:01143 const bool enable_spdy;
xunjieli186d2bf2017-04-18 13:45:47144 // Enable Brotli.
145 const bool enable_brotli;
pauljensen9041eb3c2015-12-09 12:29:01146 // Type of http cache.
147 const HttpCacheType http_cache;
[email protected]94de3e02014-06-17 00:09:51148 // Max size of http cache in bytes.
pauljensen9041eb3c2015-12-09 12:29:01149 const int http_cache_max_size;
mefbb4f45c2015-01-12 18:03:25150 // Disable caching for HTTP responses. Other information may be stored in
151 // the cache.
pauljensen9041eb3c2015-12-09 12:29:01152 const bool load_disable_cache;
[email protected]94de3e02014-06-17 00:09:51153 // Storage path for http cache and cookie storage.
pauljensen9041eb3c2015-12-09 12:29:01154 const std::string storage_path;
Misha Efimovd4ab38302018-01-30 23:56:42155 // Accept-Language request header field.
156 const std::string accept_language;
mefd1907102014-11-07 17:46:48157 // User-Agent request header field.
pauljensen9041eb3c2015-12-09 12:29:01158 const std::string user_agent;
mefc71361c2014-09-16 14:48:56159
xunjieli013145f2015-10-20 23:20:11160 // Certificate verifier for testing.
dchengfe3745e6242016-04-21 23:49:58161 std::unique_ptr<net::CertVerifier> mock_cert_verifier;
xunjieli013145f2015-10-20 23:20:11162
tbansale11aa362017-07-04 15:59:36163 // Enable Network Quality Estimator (NQE).
tbansal7018e2a2016-06-25 00:40:39164 const bool enable_network_quality_estimator;
165
kapishnikov385aa422016-07-01 20:53:02166 // Enable public key pinning bypass for local trust anchors.
167 const bool bypass_public_key_pinning_for_local_trust_anchors;
168
pauljensen9041eb3c2015-12-09 12:29:01169 // App-provided list of servers that support QUIC.
Donna Wu7ea51c22017-06-20 08:34:52170 std::vector<std::unique_ptr<QuicHint>> quic_hints;
pauljensen9041eb3c2015-12-09 12:29:01171
172 // The list of public key pins.
Donna Wu7ea51c22017-06-20 08:34:52173 std::vector<std::unique_ptr<Pkp>> pkp_list;
pauljensen9041eb3c2015-12-09 12:29:01174
mgershac5f75a2017-06-28 16:53:08175 // Enable DNS cache persistence.
176 bool enable_host_cache_persistence = false;
177
178 // Minimum time in milliseconds between writing the HostCache contents to
179 // prefs. Only relevant when |enable_host_cache_persistence| is true.
180 int host_cache_persistence_delay_ms = 60000;
181
xunjielid67295e2017-03-16 21:05:41182 // Experimental options that are recognized by the config parser.
Lei Zhang724aa16b2021-04-15 20:56:58183 std::unique_ptr<base::DictionaryValue> effective_experimental_options;
xunjielid67295e2017-03-16 21:05:41184
tbansale11aa362017-07-04 15:59:36185 // If set, forces NQE to return the set value as the effective connection
186 // type.
187 base::Optional<net::EffectiveConnectionType>
188 nqe_forced_effective_connection_type;
189
Douglas Creagera220947e2018-08-23 20:08:53190 // Preloaded Report-To headers, to preconfigure the Reporting API.
191 std::vector<PreloadedNelAndReportingHeader> preloaded_report_to_headers;
192
193 // Preloaded NEL headers, to preconfigure Network Error Logging.
194 std::vector<PreloadedNelAndReportingHeader> preloaded_nel_headers;
195
Paul Jensen6a1ea3a2018-08-24 14:46:41196 // Optional network thread priority.
197 // On Android, corresponds to android.os.Process.setThreadPriority() values.
198 // On iOS, corresponds to NSThread::setThreadPriority values.
199 const base::Optional<double> network_thread_priority;
200
mefc71361c2014-09-16 14:48:56201 private:
mgershcc6ae892017-06-20 22:33:53202 // Parses experimental options and makes appropriate changes to settings in
203 // the URLRequestContextConfig and URLRequestContextBuilder.
204 void ParseAndSetExperimentalOptions(
205 net::URLRequestContextBuilder* context_builder,
Victor Vasilieva1e66d72019-12-05 17:55:38206 net::HttpNetworkSession::Params* session_params,
207 net::QuicParams* quic_params);
mgershcc6ae892017-06-20 22:33:53208
tbansale11aa362017-07-04 15:59:36209 // Experimental options encoded as a string in a JSON format containing
210 // experiments and their corresponding configuration options. The format
211 // is a JSON object with the name of the experiment as the key, and the
212 // configuration options as the value. An example:
mmenkecf3cb2a2017-07-07 20:48:44213 // {"experiment1": {"option1": "option_value1", "option2":
214 // "option_value2",
tbansale11aa362017-07-04 15:59:36215 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
216 const std::string experimental_options;
217
mefc71361c2014-09-16 14:48:56218 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfig);
[email protected]94de3e02014-06-17 00:09:51219};
220
lilyhoughton14e2a1f12017-01-11 14:50:27221// Stores intermediate state for URLRequestContextConfig. Initializes with
222// (mostly) sane defaults, then the appropriate member variables can be
223// modified, and it can be finalized with Build().
224struct URLRequestContextConfigBuilder {
225 URLRequestContextConfigBuilder();
226 ~URLRequestContextConfigBuilder();
227
228 // Finalize state into a URLRequestContextConfig. Must only be called once,
229 // as once |mock_cert_verifier| is moved into a URLRequestContextConfig, it
230 // cannot be used again.
231 std::unique_ptr<URLRequestContextConfig> Build();
232
233 // Enable QUIC.
Renjie Tang1c718942020-06-11 23:05:38234 bool enable_quic = true;
lilyhoughton14e2a1f12017-01-11 14:50:27235 // QUIC User Agent ID.
236 std::string quic_user_agent_id = "";
237 // Enable SPDY.
238 bool enable_spdy = true;
xunjieli186d2bf2017-04-18 13:45:47239 // Enable Brotli.
240 bool enable_brotli = false;
lilyhoughton14e2a1f12017-01-11 14:50:27241 // Type of http cache.
242 URLRequestContextConfig::HttpCacheType http_cache =
243 URLRequestContextConfig::DISABLED;
244 // Max size of http cache in bytes.
245 int http_cache_max_size = 0;
246 // Disable caching for HTTP responses. Other information may be stored in
247 // the cache.
248 bool load_disable_cache = false;
249 // Storage path for http cache and cookie storage.
250 std::string storage_path = "";
Misha Efimovd4ab38302018-01-30 23:56:42251 // Accept-Language request header field.
252 std::string accept_language = "";
lilyhoughton14e2a1f12017-01-11 14:50:27253 // User-Agent request header field.
254 std::string user_agent = "";
255 // Experimental options encoded as a string in a JSON format containing
256 // experiments and their corresponding configuration options. The format
257 // is a JSON object with the name of the experiment as the key, and the
258 // configuration options as the value. An example:
259 // {"experiment1": {"option1": "option_value1", "option2": "option_value2",
260 // ...}, "experiment2: {"option3", "option_value3", ...}, ...}
261 std::string experimental_options = "{}";
lilyhoughton14e2a1f12017-01-11 14:50:27262
263 // Certificate verifier for testing.
Lei Zhang5bb12d92021-04-15 09:54:56264 std::unique_ptr<net::CertVerifier> mock_cert_verifier;
lilyhoughton14e2a1f12017-01-11 14:50:27265
266 // Enable network quality estimator.
267 bool enable_network_quality_estimator = false;
268
269 // Enable public key pinning bypass for local trust anchors.
270 bool bypass_public_key_pinning_for_local_trust_anchors = true;
271
Paul Jensen6a1ea3a2018-08-24 14:46:41272 // Optional network thread priority.
273 // On Android, corresponds to android.os.Process.setThreadPriority() values.
274 // On iOS, corresponds to NSThread::setThreadPriority values.
275 // Do not specify for other targets.
276 base::Optional<double> network_thread_priority;
277
lilyhoughton14e2a1f12017-01-11 14:50:27278 private:
279 DISALLOW_COPY_AND_ASSIGN(URLRequestContextConfigBuilder);
280};
281
[email protected]94de3e02014-06-17 00:09:51282} // namespace cronet
283
284#endif // COMPONENTS_CRONET_URL_REQUEST_CONTEXT_CONFIG_H_