Use SecureSocket.connect directly if there's no authority in Credentials (#343)

This commit is contained in:
Mehmet Fidanboylu 2020-08-27 15:06:54 -07:00 committed by GitHub
parent 5891eb81bb
commit ad2c0f6f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 13 deletions

View File

@ -75,22 +75,33 @@ class Http2ClientConnection implements connection.ClientConnection {
static const _estimatedRoundTripTime = const Duration(milliseconds: 20);
Future<ClientTransportConnection> connectTransport() async {
Future<Socket> _createSocket() async {
final securityContext = credentials.securityContext;
Socket socket = await Socket.connect(host, port);
if (securityContext == null) {
return Socket.connect(host, port);
} else {
if (options.credentials.authority == null) {
return SecureSocket.connect(host, port,
context: securityContext,
onBadCertificate: _validateBadCertificate);
} else {
// Todo(sigurdm): We want to pass supportedProtocols: ['h2']. http://dartbug.com/37950
return SecureSocket.secure(await Socket.connect(host, port),
// This is not really the host, but the authority to verify the TLC
// connection against.
//
// We don't use `this.authority` here, as that includes the port.
host: options.credentials.authority,
context: securityContext,
onBadCertificate: _validateBadCertificate);
}
}
}
Future<ClientTransportConnection> connectTransport() async {
final Socket socket = await _createSocket();
// Don't wait for io buffers to fill up before sending requests.
socket.setOption(SocketOption.tcpNoDelay, true);
if (securityContext != null) {
// Todo(sigurdm): We want to pass supportedProtocols: ['h2']. http://dartbug.com/37950
socket = await SecureSocket.secure(socket,
// This is not really the host, but the authority to verify the TLC
// connection against.
//
// We don't use `this.authority` here, as that includes the port.
host: options.credentials.authority ?? host,
context: securityContext,
onBadCertificate: _validateBadCertificate);
}
final connection = ClientTransportConnection.viaSocket(socket);
socket.done.then((_) => _abandonConnection());