@@ -169,6 +169,18 @@ class SubsonicService {
169169 }
170170
171171 HttpClient createClient () {
172+ HttpClient buildClient (SecurityContext context) {
173+ return HttpOverrides .runWithHttpOverrides (() {
174+ final client = HttpClient (context: context);
175+ client.connectionTimeout = const Duration (seconds: 15 );
176+ client.idleTimeout = const Duration (seconds: 15 );
177+ if (allowSelfSigned) {
178+ client.badCertificateCallback = (cert, host, port) => true ;
179+ }
180+ return client;
181+ }, _RealHttpOverrides ());
182+ }
183+
172184 try {
173185 final context = SecurityContext (withTrustedRoots: true );
174186
@@ -185,23 +197,10 @@ class SubsonicService {
185197 context.usePrivateKeyBytes (clientCertBytes, password: password);
186198 }
187199
188- final client = HttpClient (context: context);
189- client.connectionTimeout = const Duration (seconds: 15 );
190- client.idleTimeout = const Duration (seconds: 15 );
191- if (allowSelfSigned) {
192- client.badCertificateCallback = (cert, host, port) => true ;
193- }
194- return client;
200+ return buildClient (context);
195201 } catch (e) {
196202 debugPrint ('Failed to configure TLS: $e ' );
197-
198- final client = HttpClient ();
199- client.connectionTimeout = const Duration (seconds: 15 );
200- client.idleTimeout = const Duration (seconds: 15 );
201- if (allowSelfSigned) {
202- client.badCertificateCallback = (cert, host, port) => true ;
203- }
204- return client;
203+ return buildClient (SecurityContext (withTrustedRoots: true ));
205204 }
206205 }
207206
@@ -1111,3 +1110,6 @@ class _TlsHttpOverrides extends HttpOverrides {
11111110 @override
11121111 HttpClient createHttpClient (SecurityContext ? context) => _factory ();
11131112}
1113+
1114+ /// Bypasses [HttpOverrides.global] to create a real [HttpClient] .
1115+ class _RealHttpOverrides extends HttpOverrides {}
0 commit comments