dialTls static method
TLS connection to authority (ALPN h2). context supplies
trust material; serverName overrides SNI (defaults to
the authority host).
Implementation
static Future<Http2Transport> dialTls(String authority, SecurityContext context,
{String? serverName}) async {
final (host, port) = _splitAuthority(authority, 443);
final raw = await Socket.connect(host, port);
final secure = await SecureSocket.secure(raw,
host: serverName ?? host,
context: context,
supportedProtocols: ['h2']);
if (secure.selectedProtocol != 'h2') {
await secure.close();
throw StateError('ALPN did not negotiate h2');
}
return Http2Transport._(authority, 'https', secure);
}