ProxyConfig class

Sends requests for selected hosts through an HTTP proxy, and everything else direct.

ApiServices.init(
  ApiConfig(
    baseUrl: 'https://partner.example.net',
    proxy: ProxyConfig(
      proxy: isStaging ? 'proxy.staging.example.com:3128' : null,
      hosts: {'partner.example.net', '*.partner.example.net'},
    ),
  ),
  name: 'partner',
);

Applied through HttpClient.findProxy, so an https request to a listed host is tunnelled with CONNECT and TLS runs end to end through the tunnel: the proxy never sees the plaintext, and the certificate is still verified — against the roots in ApiConfig.pinning when the host is pinned. A proxy that terminates TLS itself will therefore be rejected by a pinned client, as it should be.

hosts matches as PinningConfig does: exactly, or *.example.com for any subdomain. Matching ignores case.

Not on web. The browser decides how to reach the network, so this setting is ignored there.

Constructors

ProxyConfig({String? proxy, Set<String> hosts = const {}})
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
hosts → Set<String>
The hosts whose requests go through proxy.
final
isActive → bool
Whether any request could go through the proxy at all.
no setter
proxy → String?
The proxy, as host:port. null sends everything direct — convenient for passing an environment's value straight through.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

appliesTo(String host) → bool
Whether requests to host go through the proxy.
findProxy(Uri uri) → String
The HttpClient.findProxy answer for uri: PROXY host:port for a listed host, DIRECT for everything else.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited