@@ -217,17 +217,14 @@ class Node extends HiveObject with Keyable {
217
217
final body = {'jsonrpc' : '2.0' , 'id' : '0' , 'method' : methodName};
218
218
219
219
try {
220
- final authenticatingClient = ProxyWrapper ().getHttpClient ();
221
- authenticatingClient.badCertificateCallback =
222
- ((X509Certificate cert, String host, int port) => true );
220
+ final client = ProxyWrapper ().getHttpIOClient ();
223
221
224
222
final jsonBody = json.encode (body);
225
223
226
- final response = await ProxyWrapper () .post (
227
- clearnetUri : rpcUri,
224
+ final response = await client .post (
225
+ rpcUri,
228
226
headers: {'Content-Type' : 'application/json' },
229
227
body: jsonBody,
230
- allowMitmMoneroBypassSSLCheck: true ,
231
228
);
232
229
// Check if we received a 401 Unauthorized response
233
230
if (response.statusCode == 401 ) {
@@ -240,7 +237,7 @@ class Node extends HiveObject with Keyable {
240
237
return ! (response['offline' ] as bool );
241
238
}
242
239
243
- final responseString = await response.transform (utf8.decoder). join () ;
240
+ final responseString = await response.body ;
244
241
245
242
if ((responseString.contains ("400 Bad Request" ) // Some other generic error
246
243
||
@@ -459,11 +456,12 @@ class DaemonRpc {
459
456
460
457
/// Perform a JSON-RPC call with Digest Authentication.
461
458
Future <Map <String , dynamic >> call (String method, Map <String , dynamic > params) async {
459
+ final client = ProxyWrapper ().getHttpIOClient ();
462
460
final DigestAuth digestAuth = DigestAuth (username, password);
463
461
464
462
// Initial request to get the `WWW-Authenticate` header.
465
- final initialResponse = await ProxyWrapper () .post (
466
- clearnetUri : Uri .parse (rpcUrl),
463
+ final initialResponse = await client .post (
464
+ Uri .parse (rpcUrl),
467
465
headers: {
468
466
'Content-Type' : 'application/json' ,
469
467
},
@@ -475,26 +473,25 @@ class DaemonRpc {
475
473
}),
476
474
);
477
475
478
- final authHeader = initialResponse.headers.value ('www-authenticate' );
479
- final responseString = await initialResponse.transform (utf8.decoder).join ();
480
-
481
- if (initialResponse.statusCode != 401 || authHeader == null ) {
482
- throw Exception ('Unexpected response: $responseString ' );
476
+ if (initialResponse.statusCode != 401 ||
477
+ ! initialResponse.headers.containsKey ('www-authenticate' )) {
478
+ throw Exception ('Unexpected response: ${initialResponse .body }' );
483
479
}
484
480
485
481
// Extract Digest details from `WWW-Authenticate` header.
486
- digestAuth.initFromAuthorizationHeader (authHeader);
482
+ final String authInfo = initialResponse.headers['www-authenticate' ]! ;
483
+ digestAuth.initFromAuthorizationHeader (authInfo);
487
484
488
485
// Create Authorization header for the second request.
489
486
String uri = Uri .parse (rpcUrl).path;
490
- String newAuthHeader = digestAuth.getAuthString ('POST' , uri);
487
+ String authHeader = digestAuth.getAuthString ('POST' , uri);
491
488
492
489
// Make the authenticated request.
493
- final authenticatedResponse = await ProxyWrapper () .post (
494
- clearnetUri : Uri .parse (rpcUrl),
490
+ final authenticatedResponse = await client .post (
491
+ Uri .parse (rpcUrl),
495
492
headers: {
496
493
'Content-Type' : 'application/json' ,
497
- 'Authorization' : newAuthHeader ,
494
+ 'Authorization' : authHeader ,
498
495
},
499
496
body: jsonEncode ({
500
497
'jsonrpc' : '2.0' ,
@@ -505,12 +502,11 @@ class DaemonRpc {
505
502
);
506
503
507
504
if (authenticatedResponse.statusCode != 200 ) {
508
- final responseString = await authenticatedResponse.transform (utf8.decoder).join ();
509
- throw Exception ('RPC call failed: $responseString ' );
505
+ throw Exception ('RPC call failed: ${authenticatedResponse .body }' );
510
506
}
511
507
512
- final responseString2 = await authenticatedResponse. transform (utf8.decoder). join ();
513
- final result = jsonDecode (responseString2 ) as Map <String , dynamic >;
508
+ final Map < String , dynamic > result =
509
+ jsonDecode (authenticatedResponse.body ) as Map <String , dynamic >;
514
510
if (result['error' ] != null ) {
515
511
throw Exception ('RPC Error: ${result ['error' ]}' );
516
512
}
0 commit comments