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
cyan committed
Nov 26, 2024 at 15:59 UTC
765ae877126a71b580c09bbf9c329f03c96e1f5d
1 file changed
+22
-1
cw_core/lib/node.dart
+22
-1
@@ -203,9 +203,30 @@ class Node extends HiveObject with Keyable {
203
headers: {'Content-Type': 'application/json'},
204
body: json.encode(body),
205
);
206
-
206
client.close();
207
208
+ if ((
209
+ response.body.contains("400 Bad Request") // Some other generic error
210
+ || response.body.contains("plain HTTP request was sent to HTTPS port") // Cloudflare
211
+ || response.headers["location"] != null // Generic reverse proxy
212
+ || response.body.contains("301 Moved Permanently") // Poorly configured generic reverse proxy
213
+ ) && !(useSSL??false)
214
+ ) {
215
+
216
+ final oldUseSSL = useSSL;
217
+ useSSL = true;
218
+ try {
219
+ final ret = await requestMoneroNode();
220
+ if (ret == true) {
221
+ await save();
222
+ return ret;
223
+ }
224
+ useSSL = oldUseSSL;
225
+ } catch (e) {
226
+ useSSL = oldUseSSL;
227
+ }
228
+ }
229
+
230
final resBody = json.decode(response.body) as Map<String, dynamic>;
231
return !(resBody['result']['offline'] as bool);
232
} catch (_) {