Skip to content

Commit 8cf8911

Browse files
committed
Use x-real-ip header instead of ip param
1 parent c4b835c commit 8cf8911

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lib/main.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ class _MyAppState extends State<MyApp> {
234234
}
235235

236236
Future<Map<String, dynamic>> _geoLookup(String ip) async {
237-
final uri = Uri.parse('https://geoip.grid.tf/?ip=${Uri.encodeQueryComponent(ip)}');
238-
final resp = await http.get(uri, headers: {'Accept': 'application/json'});
237+
final uri = Uri.parse('https://geoip.grid.tf/');
238+
final resp = await http
239+
.get(uri, headers: {'Accept': 'application/json', 'X-Real-IP': ip});
239240
if (resp.statusCode != 200) {
240241
throw Exception('geo lookup failed: ${resp.statusCode}');
241242
}
@@ -381,7 +382,14 @@ class _MyAppState extends State<MyApp> {
381382
_rawPeersText = v;
382383
_geoDebounce?.cancel();
383384
_geoDebounce = Timer(const Duration(milliseconds: 500), () async {
385+
if (!mounted) return;
384386
final currentPeers = preprocessPeers(getPeers(_rawPeersText));
387+
if (currentPeers.isEmpty) {
388+
setState(() {
389+
_peerToCountry = {};
390+
});
391+
return;
392+
}
385393
await _fetchAndGroupPeersByCountry(currentPeers);
386394
if (mounted) setState(() {});
387395
});

0 commit comments

Comments
 (0)