proxyIoClient function

IOClient proxyIoClient({
  1. Map<String, String> proxy = const {},
  2. bool badCertificateCallback(
    1. X509Certificate cert,
    2. String host,
    3. int port
    )?,
})

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 supporting http_proxy, https_proxy, all_proxy, and no_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);
}