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 15:59:22 +01:00 committed by GitHub
parent eff6616981
commit 765ae87712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -203,9 +203,30 @@ class Node extends HiveObject with Keyable {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: json.encode(body), body: json.encode(body),
); );
client.close(); 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>; final resBody = json.decode(response.body) as Map<String, dynamic>;
return !(resBody['result']['offline'] as bool); return !(resBody['result']['offline'] as bool);
} catch (_) { } catch (_) {