-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathbase_response_io.dart
More file actions
70 lines (67 loc) · 2.1 KB
/
Copy pathbase_response_io.dart
File metadata and controls
70 lines (67 loc) · 2.1 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:io';
import 'package:http/http.dart';
import 'package:http/io_client.dart';
import 'package:http_interceptor/extensions/io_streamed_response.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.
///
/// [inner] are only copied if `this` is a [IOStreamedResponse] 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,
// `IOStreamedResponse` only properties.
HttpClientResponse? inner,
}) => switch (this) {
Response res => res.copyWith(
statusCode: statusCode,
body: body,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase,
),
IOStreamedResponse res => res.copyWith(
stream: stream,
statusCode: statusCode,
contentLength: contentLength,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase,
inner: inner,
),
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',
),
};
}