copyWith method

Request copyWith({
  1. HttpMethod? method,
  2. Uri? url,
  3. Map<String, String>? headers,
  4. String? body,
  5. List<int>? bodyBytes,
  6. Encoding? encoding,
  7. bool? followRedirects,
  8. int? maxRedirects,
  9. bool? persistentConnection,
})

Creates a new instance of Request based of on this. It copies all the properties and overrides the ones sent via parameters.

Implementation

Request copyWith({
  HttpMethod? method,
  Uri? url,
  Map<String, String>? headers,
  String? body,
  List<int>? bodyBytes,
  Encoding? encoding,
  bool? followRedirects,
  int? maxRedirects,
  bool? persistentConnection,
}) {
  final copied = Request(
    method?.asString ?? this.method,
    url ?? this.url,
  )..body = this.body;

  if (body != null) {
    copied.body = body;
  }

  if (bodyBytes != null) {
    copied.bodyBytes = bodyBytes;
  }

  return copied
    ..headers.addAll(headers ?? this.headers)
    ..encoding = encoding ?? this.encoding
    ..followRedirects = followRedirects ?? this.followRedirects
    ..maxRedirects = maxRedirects ?? this.maxRedirects
    ..persistentConnection =
        persistentConnection ?? this.persistentConnection;
}