assignToHttpClientWithSecureOptions static method
void
assignToHttpClientWithSecureOptions(
- HttpClient httpClient,
- List<
ProxySettings> proxies, { - dynamic host,
- SecurityContext? context,
- bool onBadCertificate(
- X509Certificate certificate
- void keyLog(
- String line
- List<
String> ? supportedProtocols,
Assign http client connection factory to proxy connection.
Applies host
, context
, onBadCertificate
,
keyLog
and supportedProtocols
to SecureSocket if
connection is tls-over-http
Implementation
static void assignToHttpClientWithSecureOptions(
HttpClient httpClient,
List<ProxySettings> proxies,
{
dynamic host,
SecurityContext? context,
bool Function(X509Certificate certificate)? onBadCertificate,
void Function(String line)? keyLog,
List<String>? supportedProtocols,
}
) {
httpClient.connectionFactory =
(uri, proxyHost, proxyPort) async {
// Returns instance of SocksSocket which implements Socket
final client = SocksTCPClient.connect(
proxies,
InternetAddress(uri.host, type: InternetAddressType.unix),
uri.port,
);
// Secure connection after establishing Socks connection
if(uri.scheme == 'https') {
final Future<SecureSocket> secureClient;
return ConnectionTask.fromSocket(secureClient = (await client).secure(
uri.host,
context: context,
onBadCertificate: onBadCertificate,
keyLog: keyLog,
supportedProtocols: supportedProtocols,
), () async => (await secureClient).close().ignore(),);
}
// SocketConnectionTask implements ConnectionTask<Socket>
return ConnectionTask.fromSocket(client,
() async => (await client).close().ignore(),);
};
}