Closed zichangg closed 2 years ago
IOOverride
does not even allow overriding SecureSocket.startConnect
or SecureSocket.connect
, so there's no workaround at all to use a custom socket with HTTPS.
@zichangg can you please elaborate the problem? The one I am getting is that if you are unable to use existing sockets for eg. you are getting error wile connecting with locally hosted API and getting Socket Exception Error. Then to fix those issue follow the steps given below:
I have a design proposal to tackle this issue. Any feedback would be welcome: https://docs.google.com/document/d/1W8TsGXQheNrxQSulr1S3BscZ_ncUsXuPhpAlTsp6lsU/edit#heading=h.xgjl2srtytjt
I'm going to mark this as fixed by a0aeed9faad4c793c7679db3b8eed58ab1be6d5c - if that is not sufficient, please reopen.
@brianquinlan
I'm trying to use the solution added on a0aeed9 to use a SSL HTTP(S) proxy.
I have built SDK revision 9863451 with d6a4eda reverted.
final client = IOClient(HttpClient()
..findProxy = ((_) => 'PROXY username:password@au755.nordvpn.com:89')
..connectionFactory = ((url, proxyHost, proxyPort) {
// I'm assuming a SSL proxy is provided here for the sake of simplicity.
return SecureSocket.startConnect(proxyHost!, proxyPort!);
}));
await client.read(Uri.parse('https://dart.dev'))
This fails with the following error:
Unhandled exception:
NoSuchMethodError: Class '_RawSocket' has no instance getter 'closedReadEventSent'.
Receiver: Instance of '_RawSocket'
Tried calling: closedReadEventSent
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1 new _RawSecureSocket (dart:io/secure_socket.dart:527:21)
#2 _RawSecureSocket.connect (dart:io/secure_socket.dart:469:16)
#3 RawSecureSocket.secure (dart:io/secure_socket.dart:289:29)
#4 SecureSocket.secure.<anonymous closure> (dart:io/secure_socket.dart:110:30)
<asynchronous suspension>
#5 _HttpClient._openUrl.<anonymous closure> (dart:_http/http_impl.dart:2721:15)
<asynchronous suspension>
The error happens after the authentication stage; if the credentials are wrong, I receive an HTTP 407 error from the proxy server.
It's also worth noting that replacing https://dart.dev
with a plaintext HTTP website works just fine.
Hi @hacker1024 - if you change the code to not use connectionFactory
does this work? ie
final client = IOClient(HttpClient()
..findProxy = ((_) => 'PROXY username:password@au755.nordvpn.com:89');
await client.read(Uri.parse('https://dart.dev'))
If so, could you file another bug to track this issue?
@brianquinlan It does not. See: #43876.
HttpClient
is not able to reuse existingsockets
. It will always use_SecureSocket
or_Socket
(dart:io implementation ofSecureSocket
/Socket
). Self-writtenSocket
s are not allowed. Users will have to useIOOverride
as a workaround.With this feature, it grants the freedom to users to choose the underlying connection. e.g. Unix domain sockets, which was supported a while ago, can be easily installed to
HttpClient
.It also potential boosts the performance if used properly.