waitUntilReady method
Returns when target is ready, within WaitTarget.remaining.
Implementation
@override
Future<void> waitUntilReady(WaitTarget target) async {
final port = _port ?? target.exposedPorts.firstOrNull;
if (port == null) {
throw ContainerLaunchException(
'Wait.forHttp needs a published port: withExposedPorts([...])',
);
}
final client = HttpClient()
..connectionTimeout = const Duration(seconds: 2)
..badCertificateCallback = ((_, _, _) => _tls);
Uri uri() => Uri(
scheme: _tls ? 'https' : 'http',
host: target.host,
port: target.mappedPort(port),
path: _path.startsWith('/') ? _path : '/$_path',
);
try {
await target.poll('$_method $_path answering ${_expected()}', () async {
try {
final request = await client.openUrl(_method, uri())
..followRedirects = false; // the status itself counts
final response = await request.close();
await response.drain<void>();
return _accepts(response.statusCode);
} on Exception {
return false; // not listening yet, or the connection was cut
}
});
} finally {
client.close(force: true);
}
}