Request constructor

Request(
  1. {required String url,
  2. Map<String, String>? urlQueryParameters,
  3. Map<String, String> headers = const {},
  4. String? httpRequestMethod,
  5. dynamic post,
  6. int retries = 0,
  7. DateTime? creationTime}
)

Creates a Request

url must not be encoded and can include query parameters urlQueryParameters may be added and will be appended to the url headers an optional map of HTTP request headers post if set, uses POST instead of GET. Post must be one of the following:

  • a String: POST request with post as the body, encoded in utf8
  • a List of bytes: POST request with post as the body

retries if >0 will retry a failed download this many times

Implementation

Request(
    {required String url,
    Map<String, String>? urlQueryParameters,
    this.headers = const {},
    String? httpRequestMethod,
    post,
    this.retries = 0,
    DateTime? creationTime})
    : url = urlWithQueryParameters(url, urlQueryParameters),
      httpRequestMethod =
          httpRequestMethod?.toUpperCase() ?? (post == null ? 'GET' : 'POST'),
      post = post is Uint8List ? String.fromCharCodes(post) : post,
      retriesRemaining = retries,
      creationTime = creationTime ?? DateTime.now() {
  if (retries < 0 || retries > 10) {
    throw ArgumentError('Number of retries must be in range 1 through 10');
  }
  if (!validHttpMethods.contains(this.httpRequestMethod)) {
    throw ArgumentError(
        'Invalid httpRequestMethod "${this.httpRequestMethod}": Must be one of ${validHttpMethods.join(', ')}');
  }
}