diff --git a/components/cronet/url_request_context_config.cc b/components/cronet/url_request_context_config.cc index 8da024badd93ab..1f52d31458f7da 100644 --- a/components/cronet/url_request_context_config.cc +++ b/components/cronet/url_request_context_config.cc @@ -211,6 +211,10 @@ const char kDisableTlsZeroRtt[] = "disable_tls_zero_rtt"; // underlying OS. const char kSpdyGoAwayOnIpChange[] = "spdy_go_away_on_ip_change"; +// Use a StandaloneResolver with the provided DNS over HTTPS configs. Other +// values are left at the defaults. TODO: Should we offer more of the config? +const char kDnsOverHttpsConfig[] = "dns_over_https_config"; + // Whether the connection status of all bidirectional streams (created through // the Cronet engine) should be monitored. // The value must be an integer (> 0) and will be interpreted as a suggestion @@ -765,6 +769,30 @@ void URLRequestContextConfig::SetContextBuilderExperimentalOptions( continue; } session_params->spdy_go_away_on_ip_change = iter->second.GetBool(); + } else if (iter->first == kDnsOverHttpsConfig) { + if (!iter->second.is_dict()) { + LOG(ERROR) << "\"" << iter->first << "\" config params \"" + << iter->second << "\" is not a dictionary value"; + effective_experimental_options.Remove(iter->first); + continue; + } + + net::DnsConfigOverrides overrides = net::DnsConfigOverrides::CreateOverridingEverythingWithDefaults(); + // Envoy does this + overrides.secure_dns_mode = net::SecureDnsMode::kSecure; + + // This is a little silly, Dict -> JSON -> Dict + std::string temp; + base::JSONWriter::Write(iter->second.GetDict(), &temp); + overrides.dns_over_https_config = net::DnsOverHttpsConfig::FromString(temp); + + net::HostResolver::ManagerOptions host_resolver_manager_options; + host_resolver_manager_options.dns_config_overrides = overrides; + std::unique_ptr host_resolver; + host_resolver = net::HostResolver::CreateStandaloneResolver( + net::NetLog::Get(), std::move(host_resolver_manager_options)); + + context_builder->set_host_resolver(std::move(host_resolver)); } else { LOG(WARNING) << "Unrecognized Cronet experimental option \"" << iter->first << "\" with params \"" << iter->second;