You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1b58049
Browse filesBrowse the repository at this point in the historyBrowse files
[cronet_http] Add DNS configuration options to CronetEngine.build
Expose Cronet DnsOptions through new CronetEngine.build parameters:
useBuiltInDnsResolver, enableStaleDns, persistHostCache and
persistHostCachePeriod.
Cronet enables QUIC by default, and with QUIC enabled it resolves hosts
through its built-in DNS resolver. On some cellular networks and in
background isolates (e.g. WorkManager) that resolver fails with
ERROR_HOSTNAME_NOT_RESOLVED while the system resolver works.
useBuiltInDnsResolver: false forces the system resolver;
enableStaleDns/persistHostCache allow a freshly created engine to serve
recently used hosts from a persisted cache.
setDnsOptions is available on the stable CronetEngine.Builder in both
cronet-api artifacts the plugin ships (play-services and embedded), and
the Java API layer transparently falls back to an experimental-options
JSON patch on implementations that do not support DnsOptions natively,
so no experimental bindings are required.
Helps with dart-lang#1217
Co-Authored-By: Claude Fable 5 <[email protected]>
Copy file name to clipboardExpand all lines: pkgs/cronet_http/lib/src/cronet_client.dart
+59-1Lines changed: 59 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -246,6 +246,30 @@ class CronetEngine {
246
246
/// of (host, port, alternativePort) that indicates that the host supports
247
247
/// QUIC. Note that [CacheMode.disk] or [CacheMode.diskNoHttp] is needed to
248
248
/// take advantage of 0-RTT connection establishment between sessions.
249
+
///
250
+
/// [useBuiltInDnsResolver] controls whether the engine uses Cronet's
251
+
/// built-in DNS resolver instead of the system resolver. The built-in
252
+
/// resolver is only used when QUIC is enabled, which it is by default.
253
+
/// Setting this to `false` forces the system resolver, which can work
254
+
/// around host resolution failures (`ERROR_HOSTNAME_NOT_RESOLVED`) seen
255
+
/// with QUIC on some cellular networks and in background isolates.
256
+
///
257
+
/// [enableStaleDns] controls whether the engine may use expired entries
258
+
/// from its host cache while a new resolution is in flight. Like
259
+
/// [useBuiltInDnsResolver], this only takes effect when QUIC is enabled.
260
+
///
261
+
/// [persistHostCache] controls whether the engine's host cache is
262
+
/// persisted to disk so that a freshly created engine (for example in a
263
+
/// newly spawned isolate) can resolve recently used hosts without a live
264
+
/// DNS query. Requires [storagePath] to be set.
265
+
///
266
+
/// [persistHostCachePeriod] sets how often the host cache is written to
267
+
/// disk when [persistHostCache] is `true`.
268
+
///
269
+
/// See [DnsOptions](https://developer.android.com/develop/connectivity/cronet/reference/org/chromium/net/DnsOptions)
270
+
/// for details on the DNS configuration options. On devices whose Cronet
271
+
/// implementation does not support DNS options natively, they are applied
272
+
/// through Cronet's experimental options fallback.
249
273
staticCronetEnginebuild(
250
274
{CacheMode? cacheMode,
251
275
int? cacheMaxSize,
@@ -255,7 +279,11 @@ class CronetEngine {
255
279
bool? enableQuic,
256
280
String? storagePath,
257
281
String? userAgent,
258
-
List<(String, int, int)>? quicHints}) {
282
+
List<(String, int, int)>? quicHints,
283
+
bool? useBuiltInDnsResolver,
284
+
bool? enableStaleDns,
285
+
bool? persistHostCache,
286
+
Duration? persistHostCachePeriod}) {
259
287
try {
260
288
returnusing((arena) {
261
289
final builder = jb.CronetEngine$Builder(
@@ -308,6 +336,36 @@ class CronetEngine {
308
336
}
309
337
}
310
338
339
+
if (useBuiltInDnsResolver !=null||
340
+
enableStaleDns !=null||
341
+
persistHostCache !=null||
342
+
persistHostCachePeriod !=null) {
343
+
if (jb.DnsOptions.builder() casefinal dnsOptionsBuilder?) {
0 commit comments