safeUrlCheck function

Future<bool> safeUrlCheck(
  1. Uri url, {
  2. int maxRedirects = 8,
  3. String userAgent = defaultUserAgent,
  4. HttpClient? client,
  5. RetryOptions retryOptions = const RetryOptions(maxAttempts: 3),
  6. Duration timeout = const Duration(seconds: 90),
})

Check if url is available, without allowing access to private networks.

This will make a HEAD request to url with given userAgent, following redirects if the hostname of URLs do not resolve to a private IP address.

Each I/O is set to timeout after timeout duration. This coupled with the large number of retries allow means that this operation can be slow.

It is good practice to set a custom userAgent, this allows servers to see which bots are requesting their resources. This package defaults to the following user-agent:

User-Agent: package:safe_url_check/1.0.0 (+https://github.com/google/dart-neats/tree/master/safe_url_check)

Implementation

Future<bool> safeUrlCheck(
  Uri url, {
  int maxRedirects = 8,
  String userAgent = defaultUserAgent,
  HttpClient? client,
  RetryOptions retryOptions = const RetryOptions(maxAttempts: 3),
  Duration timeout = const Duration(seconds: 90),
}) async {
  return doSafeUrlCheck(
    url,
    maxRedirects: maxRedirects,
    userAgent: userAgent,
    client: client,
    retryOptions: retryOptions,
    timeout: timeout,
  );
}