mirror of https://github.com/grpc/grpc-dart.git
Use SecureSocket.connect directly if there's no authority in Credentials (#343)
This commit is contained in:
parent
5891eb81bb
commit
ad2c0f6f3e
|
|
@ -75,22 +75,33 @@ class Http2ClientConnection implements connection.ClientConnection {
|
||||||
|
|
||||||
static const _estimatedRoundTripTime = const Duration(milliseconds: 20);
|
static const _estimatedRoundTripTime = const Duration(milliseconds: 20);
|
||||||
|
|
||||||
Future<ClientTransportConnection> connectTransport() async {
|
Future<Socket> _createSocket() async {
|
||||||
final securityContext = credentials.securityContext;
|
final securityContext = credentials.securityContext;
|
||||||
Socket socket = await Socket.connect(host, port);
|
if (securityContext == null) {
|
||||||
// Don't wait for io buffers to fill up before sending requests.
|
return Socket.connect(host, port);
|
||||||
socket.setOption(SocketOption.tcpNoDelay, true);
|
} else {
|
||||||
if (securityContext != null) {
|
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
|
// Todo(sigurdm): We want to pass supportedProtocols: ['h2']. http://dartbug.com/37950
|
||||||
socket = await SecureSocket.secure(socket,
|
return SecureSocket.secure(await Socket.connect(host, port),
|
||||||
// This is not really the host, but the authority to verify the TLC
|
// This is not really the host, but the authority to verify the TLC
|
||||||
// connection against.
|
// connection against.
|
||||||
//
|
//
|
||||||
// We don't use `this.authority` here, as that includes the port.
|
// We don't use `this.authority` here, as that includes the port.
|
||||||
host: options.credentials.authority ?? host,
|
host: options.credentials.authority,
|
||||||
context: securityContext,
|
context: securityContext,
|
||||||
onBadCertificate: _validateBadCertificate);
|
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);
|
||||||
|
|
||||||
final connection = ClientTransportConnection.viaSocket(socket);
|
final connection = ClientTransportConnection.viaSocket(socket);
|
||||||
socket.done.then((_) => _abandonConnection());
|
socket.done.then((_) => _abandonConnection());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue