forked from CodingAleCR/http_interceptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_response_none.dart
More file actions
52 lines (50 loc) · 1.64 KB
/
base_response_none.dart
File metadata and controls
52 lines (50 loc) · 1.64 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
import 'package:http/http.dart';
import './response.dart';
import './streamed_response.dart';
// Extends [BaseRequest] to provide copied instances.
extension BaseResponseCopyWith on BaseResponse {
/// Creates a new instance of [BaseResponse] based of on `this`. It copies
/// all the properties and overrides the ones sent via parameters.
///
/// [body] are only copied if `this` is a [Response] instance.
///
/// [stream] and [contentLength] are only copied if `this` is a
/// [StreamedResponse] instance.
BaseResponse copyWith({
int? statusCode,
BaseRequest? request,
Map<String, String>? headers,
bool? isRedirect,
bool? persistentConnection,
String? reasonPhrase,
// `Response` only variables.
String? body,
// `StreamedResponse` only properties.
Stream<List<int>>? stream,
int? contentLength,
}) =>
switch (this) {
Response res => res.copyWith(
statusCode: statusCode,
body: body,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase,
),
StreamedResponse res => res.copyWith(
stream: stream,
statusCode: statusCode,
contentLength: contentLength,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase,
),
_ => throw UnsupportedError(
'Cannot copy unsupported type of response $runtimeType',
),
};
}