createTlsHttpClient function
Client
createTlsHttpClient({
- SecurityContext? securityContext,
- bool allowInvalidCertificates = false,
Creates an http.Client for a server that uses TLS.
securityContext is the context the TLS handshake is made with. When
allowInvalidCertificates is true the certificate of the server is not
verified, which is what upstream issue #80 asked for: a self signed
certificate, or one issued for another host, is accepted.
Skipping the verification is dangerous — the connection is not protected against a man in the middle. Use it only against a server you trust, and prefer a certificate that is valid.
The client is meant to be handed to the Minio constructor:
final minio = Minio(
endPoint: 'minio.example.com',
accessKey: '...',
secretKey: '...',
httpClient: createTlsHttpClient(allowInvalidCertificates: true),
);
Implementation
http.Client createTlsHttpClient({
SecurityContext? securityContext,
bool allowInvalidCertificates = false,
}) {
final context = securityContext ?? SecurityContext(withTrustedRoots: true);
final inner = HttpClient(context: context);
if (allowInvalidCertificates) {
inner.badCertificateCallback = (cert, host, port) => true;
}
return IOClient(inner);
}