ConsoleClient constructor

ConsoleClient(
  1. {String? proxy,
  2. String proxyFn(
    1. Uri uri
    )?,
  3. dynamic headers,
  4. Duration? idleTimeout,
  5. int? maxConnectionsPerHost,
  6. bool? autoUncompress,
  7. String? userAgent,
  8. bool? ignoreBadCertificates}
)

HTTP Client in console (server) environment.

Set proxy for static http proxy, or proxyFn for dynamic http proxy. Return format should be e.g. ""PROXY host:port; PROXY host2:port2; DIRECT"

Implementation

factory ConsoleClient({
  String? proxy,
  String Function(Uri uri)? proxyFn,

  /* Headers | Map */
  dynamic headers,

  /// The idle timeout of non-active persistent (keep-alive) connections.
  Duration? idleTimeout,

  /// the maximum number of live connections, to a single host.
  int? maxConnectionsPerHost,

  /// Whether the body of a response will be automatically uncompressed.
  bool? autoUncompress,

  /// The default value of the `User-Agent` header for all requests.
  /// Set to empty string to disable setting the User-Agent header automatically.
  String? userAgent,

  /// Whether to silently ignore bad certificates.
  /// Use it only on known servers with demo/expired SSL certs.
  bool? ignoreBadCertificates,
}) {
  ignoreBadCertificates ??= false;
  final delegate = io.HttpClient();
  if (proxy != null) {
    delegate.findProxy = (uri) => proxy;
  } else if (proxyFn != null) {
    delegate.findProxy = proxyFn;
  }
  if (idleTimeout != null) {
    delegate.idleTimeout = idleTimeout;
  }
  if (maxConnectionsPerHost != null) {
    delegate.maxConnectionsPerHost = maxConnectionsPerHost;
  }
  if (autoUncompress != null) {
    delegate.autoUncompress = autoUncompress;
  }
  if (userAgent != null) {
    delegate.userAgent = userAgent.isEmpty ? null : userAgent;
  }
  if (ignoreBadCertificates) {
    delegate.badCertificateCallback = (cert, host, port) => true;
  }
  return ConsoleClient._(delegate, wrapHeaders(headers, clone: true));
}