forked from CodingAleCR/http_interceptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipart_request.dart
More file actions
40 lines (36 loc) · 1.31 KB
/
multipart_request.dart
File metadata and controls
40 lines (36 loc) · 1.31 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
34
35
36
37
38
39
40
import 'package:http/http.dart';
import 'package:http_interceptor/http/http_methods.dart';
/// Extends [MultipartRequest] to provide copied instances.
extension MultipartRequestCopyWith on MultipartRequest {
/// Creates a new instance of [MultipartRequest] based of on `this`. It copies
/// all the properties and overrides the ones sent via parameters.
MultipartRequest copyWith({
HttpMethod? method,
Uri? url,
Map<String, String>? headers,
Map<String, String>? fields,
List<MultipartFile>? files,
bool? followRedirects,
int? maxRedirects,
bool? persistentConnection,
}) {
final MultipartRequest clonedRequest =
MultipartRequest(method?.asString ?? this.method, url ?? this.url)
..headers.addAll(headers ?? this.headers)
..fields.addAll(fields ?? this.fields);
for (final MultipartFile file in this.files) {
clonedRequest.files.add(MultipartFile(
file.field,
file.finalize(),
file.length,
filename: file.filename,
contentType: file.contentType,
));
}
this.persistentConnection =
persistentConnection ?? this.persistentConnection;
this.followRedirects = followRedirects ?? this.followRedirects;
this.maxRedirects = maxRedirects ?? this.maxRedirects;
return clonedRequest;
}
}