-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathbase_request.dart
More file actions
70 lines (67 loc) · 2.04 KB
/
Copy pathbase_request.dart
File metadata and controls
70 lines (67 loc) · 2.04 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import 'dart:convert';
import 'package:http/http.dart';
import 'package:http_interceptor/http/http_methods.dart';
import './multipart_request.dart';
import './request.dart';
import './streamed_request.dart';
/// Extends [BaseRequest] to provide copied instances.
extension BaseRequestCopyWith on BaseRequest {
/// Creates a new instance of [BaseRequest] based of on `this`. It copies
/// all the properties and overrides the ones sent via parameters.
///
/// [body] and [encoding] are only copied if `this` is a [Request] instance.
///
/// [fields] and [files] are only copied if `this` is a [MultipartRequest]
/// instance.
///
/// [stream] are only copied if `this` is a [StreamedRequest] instance.
BaseRequest copyWith({
HttpMethod? method,
Uri? url,
Map<String, String>? headers,
bool? followRedirects,
int? maxRedirects,
bool? persistentConnection,
// Request only variables.
dynamic body,
Encoding? encoding,
// MultipartRequest only properties.
Map<String, String>? fields,
List<MultipartFile>? files,
// StreamedRequest only properties.
Stream<List<int>>? stream,
}) => switch (this) {
Request req => req.copyWith(
method: method,
url: url,
headers: headers,
body: body,
encoding: encoding,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
persistentConnection: persistentConnection,
),
StreamedRequest req => req.copyWith(
method: method,
url: url,
headers: headers,
stream: stream,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
persistentConnection: persistentConnection,
),
MultipartRequest req => req.copyWith(
method: method,
url: url,
headers: headers,
fields: fields,
files: files,
followRedirects: followRedirects,
maxRedirects: maxRedirects,
persistentConnection: persistentConnection,
),
_ => throw UnsupportedError(
'Cannot copy unsupported type of request $runtimeType',
),
};
}