copyWith method

StreamedRequest copyWith({
  1. HttpMethod? method,
  2. Uri? url,
  3. Map<String, String>? headers,
  4. Stream<List<int>>? stream,
  5. bool? followRedirects,
  6. int? maxRedirects,
  7. bool? persistentConnection,
})

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

Implementation

StreamedRequest copyWith({
  HttpMethod? method,
  Uri? url,
  Map<String, String>? headers,
  Stream<List<int>>? stream,
  bool? followRedirects,
  int? maxRedirects,
  bool? persistentConnection,
}) {
  final req = StreamedRequest(
    method?.asString ?? this.method,
    url ?? this.url,
  )
    ..headers.addAll(headers ?? this.headers)
    ..followRedirects = followRedirects ?? this.followRedirects
    ..maxRedirects = maxRedirects ?? this.maxRedirects
    ..persistentConnection =
        persistentConnection ?? this.persistentConnection;

  if (stream != null) {
    stream.listen((data) {
      req.sink.add(data);
    });
    finalize().listen((data) {
      req.sink.add(data);
    });
  }

  return req;
}