proxyIoClient function
Creates a raw, non-intercepted IOClient configured with optional proxy rules
and custom SSL certificate validation settings.
Unlike interceptedClient, this client is not wrapped by any interceptors, making it ideal for performance-sensitive requests (e.g., SSE, AI token streaming, large file transfers) or as the default client in MethodSwitchingClient.
proxy: Environment map supportinghttp_proxy,https_proxy,all_proxy, andno_proxy.badCertificateCallback: Optional callback to customize or bypass SSL certificate verification (e.g. self-signed certificates in local development).
Implementation
IOClient proxyIoClient({
Map<String, String> proxy = const {},
bool Function(io.X509Certificate cert, String host, int port)?
badCertificateCallback,
}) {
final httpClient = io.HttpClient();
if (proxy.isNotEmpty) {
httpClient.findProxy = (url) {
return io.HttpClient.findProxyFromEnvironment(url, environment: proxy);
};
}
if (badCertificateCallback != null) {
httpClient.badCertificateCallback = badCertificateCallback;
}
return IOClient(httpClient);
}