io library
Pinned clients for code that does not go through ApiServices — a
WebSocket, a SignalR hub, any library that takes its own HttpClient or
package:http client.
import 'package:baaba_api_handler/io.dart';
Mobile and desktop only. This library imports dart:io, which does
not exist on web — import it only from code that never compiles for web,
or behind your own conditional import. The core library,
package:baaba_api_handler/baaba_api_handler.dart, stays web-safe and
falls back to the browser's TLS there.
The clients trust the given roots and nothing else, exactly as
ApiConfig.pinning does: no badCertificateCallback, so a certificate
that does not chain to them fails the handshake. Reuse the roots you
already gave ApiConfig with PinningConfig.rootsFor:
final roots = pinning.rootsFor('hub.example.com')!;
// web_socket_channel
final channel = IOWebSocketChannel.connect(
Uri.parse('wss://hub.example.com/ws'),
customClient: pinnedHttpClient(roots),
);
// signalr_netcore and others that take a package:http client
final hub = HubConnectionBuilder()
.withUrl(
'https://hub.example.com/hub',
options: HttpConnectionOptions(client: pinnedIoClient(roots)),
)
.build();
Classes
- IOClient
-
A
dart:io-based HTTPClient. - PinningConfig
- Certificate pinning by CA: each host is trusted only if its certificate chains to one of the roots listed for it.
- ProxyConfig
- Sends requests for selected hosts through an HTTP proxy, and everything else direct.
Enums
- UnlistedHostPolicy
- What a pinned client does with a host PinningConfig does not list.
Functions
-
pinnedHttpClient(
List< String> rootsPem, {ProxyConfig? proxy}) → HttpClient -
A
dart:ioHttpClient that trustsrootsPemand nothing else. -
pinnedIoClient(
List< String> rootsPem, {ProxyConfig? proxy}) → IOClient -
A
package:httpclient that trustsrootsPemand nothing else — an IOClient over pinnedHttpClient.