HttpFetcher class final
Fetches files over HTTPS.
- Only
https:(plainhttp:to this machine, for testing a catalog locally) — for the address asked for and for every redirect; a fetch that began onhttps:never follows a redirect tohttp:. - Up to 5 redirects; 20 s to connect, timeout of silence at most, and a deadline for the whole fetch (deadlineFor): a server that sends a byte now and then can't keep it going for ever. 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 withclient(tests pass a fake), and giving up on a server that stays silent fortimeout.
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, ByteRange? range, Duration? deadline}) → Future<FetchResponse> -
GETs
uriwithheaders. A 304 (theIf-None-Matchcopy is still good) comes back with an empty body; any other status but 200 throws a FetchException, as does a body overmaxBytes(defaultMaxBytes when null), a redirect away fromhttps:, a timeout and a failed connection. -
getCached(
Uri uri, {required File? cache, required FutureOr< String> decode(Uint8List bytes), bool refresh = false, int? maxBytes, CancelToken? cancel}) → Future<CachedText> -
The text at
uri, kept incache(with its ETag beside it) so an unchanged file costs one small request and the last copy still reads offline.refreshasks again even when the copy would do.decodeturns the bytes into text — it may take its time (fetching what the text names, say) — 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
Static Methods
-
deadlineFor(
int maxBytes) → Duration -
How long a fetch of up to
maxBytesmay take in all, retries and redirects included: two minutes, and as long again asmaxBytestakes at minBytesPerSecond.
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.
- minBytesPerSecond → const int
- The slowest a download may average before its deadline passes: 32 KiB a second, a slow mobile connection.