-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathstreamed_request.dart
More file actions
33 lines (30 loc) · 1.11 KB
/
streamed_request.dart
File metadata and controls
33 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import 'package:http/http.dart';
import 'package:http_interceptor/http/http_methods.dart';
/// Extends [StreamedRequest] to provide copied instances.
extension StreamedRequestCopyWith on StreamedRequest {
/// Creates a new instance of [StreamedRequest] based of on `this`. It copies
/// all the properties and overrides the ones sent via parameters.
Future<StreamedRequest> copyWith({
HttpMethod? method,
Uri? url,
Map<String, String>? headers,
Stream<List<int>>? stream,
bool? followRedirects,
int? maxRedirects,
bool? persistentConnection,
}) async {
final StreamedRequest clonedRequest = StreamedRequest(
method?.toString() ?? this.method,
url ?? this.url,
)
..followRedirects = followRedirects ?? this.followRedirects
..maxRedirects = maxRedirects ?? this.maxRedirects
..persistentConnection = persistentConnection ?? this.persistentConnection
..headers.addAll(headers ?? this.headers);
await for (List<int> chunk in stream ?? finalize()) {
clonedRequest.sink.add(chunk);
}
clonedRequest.sink.close();
return clonedRequest;
}
}