mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 20:49:26 +01:00
31 lines
751 B
Dart
31 lines
751 B
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/io_client.dart';
|
|
|
|
import 'package:fluffychat/config/isrg_x1.dart';
|
|
|
|
class CustomHttpClient {
|
|
static HttpClient customHttpClient(String? cert) {
|
|
final context = SecurityContext.defaultContext;
|
|
|
|
try {
|
|
if (cert != null) {
|
|
final bytes = utf8.encode(cert);
|
|
context.setTrustedCertificatesBytes(bytes);
|
|
}
|
|
} on TlsException catch (e) {
|
|
if (e.osError != null &&
|
|
e.osError!.message.contains('CERT_ALREADY_IN_HASH_TABLE')) {
|
|
} else {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
return HttpClient(context: context);
|
|
}
|
|
|
|
static http.Client createHTTPClient() => IOClient(customHttpClient(ISRG_X1));
|
|
}
|