isResponseOnline static method
Future<bool>
isResponseOnline(
- String url, {
- Duration? timeout,
- int? timeoutMillis,
- CheckMethod checkMethod = CheckMethod.OPTIONS,
Implementation
static Future<bool> isResponseOnline(String url,
{Duration? timeout,
int? timeoutMillis,
CheckMethod checkMethod = CheckMethod.OPTIONS}) async {
final future =
checkMethod == CheckMethod.OPTIONS ? options(url) : head(url);
if (timeoutMillis != null) timeout = Duration(milliseconds: timeoutMillis);
final response = await (timeout == null
? future
: future.timeout(timeout,
onTimeout: () => http.Response('', HttpStatus.requestTimeout)));
switch (response.statusCode) {
case HttpStatus.notFound:
case HttpStatus.requestTimeout:
case HttpStatus.gatewayTimeout:
case HttpStatus.networkConnectTimeoutError:
return false;
}
return true;
}