Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions components/cronet/url_request_context_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having type issues here, they are IIRC a base::DictValue and a base::Dict::Value which seem to not be exactly compatible. There's probably a more straightforward way to do the needed conversion, but this is what I did to get it working for now

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<net::HostResolver> 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;
Expand Down