get method
Future<FetchResponse>
get(
- Uri uri, {
- Map<
String, String> headers = const {}, - ByteProgress? onProgress,
- CancelToken? cancel,
- int? maxBytes,
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.
Implementation
Future<FetchResponse> get(
Uri uri, {
Map<String, String> headers = const {},
ByteProgress? onProgress,
CancelToken? cancel,
int? maxBytes,
}) async {
if (!isFetchAllowed(uri)) {
throw FetchException('Downloads must use https.', uri: uri);
}
for (var attempt = 1; ; attempt++) {
cancel?.check();
final (response, retryAfter) = await _attempt(
uri,
headers: headers,
onProgress: onProgress,
cancel: cancel,
maxBytes: maxBytes ?? defaultMaxBytes,
attempt: attempt,
);
if (response != null) return response;
await _pause(retryAfter!, cancel);
}
}