Automatically upgrade non-SSL nodes to SSL if they fail (#1757)

* Automatically upgrade non-SSL nodes to SSL if they fail

* another ssl catch

* [skip ci] pr fixes
This commit is contained in:
cyan
2024-11-26 16:59:22 +02:00
committed by GitHub
parent eff6616981
commit 765ae87712
+22 -1
View File
@@ -203,9 +203,30 @@ class Node extends HiveObject with Keyable {
headers: {'Content-Type': 'application/json'},
body: json.encode(body),
);
client.close();
if ((
response.body.contains("400 Bad Request") // Some other generic error
|| response.body.contains("plain HTTP request was sent to HTTPS port") // Cloudflare
|| response.headers["location"] != null // Generic reverse proxy
|| response.body.contains("301 Moved Permanently") // Poorly configured generic reverse proxy
) && !(useSSL??false)
) {
final oldUseSSL = useSSL;
useSSL = true;
try {
final ret = await requestMoneroNode();
if (ret == true) {
await save();
return ret;
}
useSSL = oldUseSSL;
} catch (e) {
useSSL = oldUseSSL;
}
}
final resBody = json.decode(response.body) as Map<String, dynamic>;
return !(resBody['result']['offline'] as bool);
} catch (_) {