HttpFetcher class final

Fetches files over HTTPS.

  • Only https: (plain http: to this machine, for testing a catalog locally) — for the address asked for and for every redirect; a fetch that began on https: never follows a redirect to http:.
  • Up to 5 redirects; 20 s to connect, timeout of silence at most. Credentials and cookies in the headers only go to the address's own origin.
  • Waits and retries, up to 3 times, when a server says to slow down (429 or 503, honouring Retry-After).
  • Stops on CancelToken, and refuses a download larger than allowed before and while reading it, without reading the rest.
  • Every failure is a FetchException (or CancelledException).

Constructors

HttpFetcher({required String userAgent, HttpClient client()?, Duration timeout = const Duration(seconds: 60)})
A fetcher announcing itself as userAgent, making connections with client (tests pass a fake), and giving up on a server that stays silent for timeout.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
timeout → Duration
How long a server may stay silent — before answering, or between two pieces of a download — before the fetch fails.
final
userAgent → String
What it tells servers it is.
final

Methods

get(Uri uri, {Map<String, String> headers = const {}, ByteProgress? onProgress, CancelToken? cancel, int? maxBytes}) → Future<FetchResponse>
GETs uri with headers. A 304 (the If-None-Match copy is still good) comes back with an empty body; any other status but 200 throws a FetchException, as does a body over maxBytes (defaultMaxBytes when null), a redirect away from https:, a timeout and a failed connection.
getCached(Uri uri, {required File? cache, required String decode(Uint8List bytes), bool refresh = false, int? maxBytes, CancelToken? cancel}) → Future<CachedText>
The text at uri, kept in cache (with its ETag beside it) so an unchanged file costs one small request and the last copy still reads offline. refresh asks again even when the copy would do. decode turns the bytes into text, and may throw an Exception to refuse them; the cached copy is then used, as when offline.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

defaultMaxBytes → const int
The largest body get reads unless told otherwise: 1 GiB. A body is held in memory, so there is always a limit.
defaultMaxTextBytes → const int
The largest text getCached reads unless told otherwise: 64 MiB.