Skip to content

Commit cafc846

Browse files
committed
feat: use HEAD request for ping and leak detection
1 parent 8c26652 commit cafc846

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/bloc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class AppBloc with AppSystemTray {
142142
_replaceLeakItemInChecklist(item);
143143
try {
144144
final url = Uri.parse(item.url);
145-
final response = await _client.get(url).timeout(const Duration(seconds: 10));
145+
final response = await _client.head(url).timeout(const Duration(seconds: 10));
146146
if (response.statusCode == 200) {
147147
item.status = LeakStatus.passed;
148148
} else {
@@ -201,7 +201,7 @@ class AppBloc with AppSystemTray {
201201
try {
202202
_isPingingGoogle = true;
203203
final url = Uri.parse('https://google.com');
204-
await _client.get(url).timeout(const Duration(seconds: 5));
204+
await _client.head(url).timeout(const Duration(seconds: 5));
205205
} on TimeoutException {
206206
_isPingingGoogle = false;
207207
_checkNetworkConnectivity();

lib/utils/http.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class HttpUtils {
1313
HttpHeaders.connectionHeader: 'keep-alive', // Ensure keep-alive headers
1414
});
1515
try {
16-
await _dio.get(url).timeout(timeout); // just a warm up connection to get a reliable result
16+
await _dio.head(url).timeout(timeout); // just a warm up connection to get a reliable result
1717
final firstTime = DateTime.now().millisecondsSinceEpoch;
18-
final response = await _dio.get(url).timeout(timeout);
18+
final response = await _dio.head(url).timeout(timeout);
1919
final secondTime = DateTime.now().millisecondsSinceEpoch;
2020
if (response.statusCode == 200 || response.statusCode == 204) {
2121
return (secondTime - firstTime).toDouble();

0 commit comments

Comments
 (0)