@@ -10,6 +10,14 @@ final class HttpProfileProxyData {
10
10
final bool ? _isDirect;
11
11
final int ? _port;
12
12
13
+ String ? get host => _host;
14
+
15
+ String ? get username => _username;
16
+
17
+ bool ? get isDirect => _isDirect;
18
+
19
+ int ? get port => _port;
20
+
13
21
HttpProfileProxyData ({
14
22
String ? host,
15
23
String ? username,
@@ -20,6 +28,14 @@ final class HttpProfileProxyData {
20
28
_isDirect = isDirect,
21
29
_port = port;
22
30
31
+ static HttpProfileProxyData _fromJson (Map <String , dynamic > json) =>
32
+ HttpProfileProxyData (
33
+ host: json['host' ] as String ? ,
34
+ username: json['username' ] as String ? ,
35
+ isDirect: json['isDirect' ] as bool ? ,
36
+ port: json['port' ] as int ? ,
37
+ );
38
+
23
39
Map <String , dynamic > _toJson () => < String , dynamic > {
24
40
if (_host != null ) 'host' : _host,
25
41
if (_username != null ) 'username' : _username,
@@ -46,20 +62,43 @@ final class HttpProfileRequestData {
46
62
/// This information is meant to be used for debugging.
47
63
///
48
64
/// It can contain any arbitrary data as long as the values are of type
49
- /// [String] or [int] . For example:
50
- /// { 'localPort': 1285, 'remotePort': 443, 'connectionPoolId': '21x23' }
51
- set connectionInfo (Map <String , dynamic /*String|int*/ > value) {
65
+ /// [String] or [int] .
66
+ ///
67
+ /// This field can only be modified by assigning a Map to it. That is:
68
+ /// ```dart
69
+ /// // Valid
70
+ /// profile?.requestData.connectionInfo = {
71
+ /// 'localPort': 1285,
72
+ /// 'remotePort': 443,
73
+ /// 'connectionPoolId': '21x23',
74
+ /// };
75
+ ///
76
+ /// // Invalid
77
+ /// profile?.requestData.connectionInfo?['localPort'] = 1285;
78
+ /// ```
79
+ set connectionInfo (Map <String , dynamic /*String|int*/ >? value) {
52
80
_checkAndUpdate ();
53
- for (final v in value.values) {
54
- if (! (v is String || v is int )) {
55
- throw ArgumentError (
56
- 'The values in connectionInfo must be of type String or int.' ,
57
- );
81
+ if (value == null ) {
82
+ _requestData.remove ('connectionInfo' );
83
+ } else {
84
+ for (final v in value.values) {
85
+ if (! (v is String || v is int )) {
86
+ throw ArgumentError (
87
+ 'The values in connectionInfo must be of type String or int.' ,
88
+ );
89
+ }
58
90
}
91
+ _requestData['connectionInfo' ] = {...value};
59
92
}
60
- _requestData['connectionInfo' ] = {...value};
61
93
}
62
94
95
+ Map <String , dynamic /*String|int*/ >? get connectionInfo =>
96
+ _requestData['connectionInfo' ] == null
97
+ ? null
98
+ : UnmodifiableMapView (
99
+ _requestData['connectionInfo' ] as Map <String , dynamic >,
100
+ );
101
+
63
102
/// The content length of the request, in bytes.
64
103
set contentLength (int ? value) {
65
104
_checkAndUpdate ();
@@ -70,12 +109,20 @@ final class HttpProfileRequestData {
70
109
}
71
110
}
72
111
112
+ int ? get contentLength => _requestData['contentLength' ] as int ? ;
113
+
73
114
/// Whether automatic redirect following was enabled for the request.
74
- set followRedirects (bool value) {
115
+ set followRedirects (bool ? value) {
75
116
_checkAndUpdate ();
76
- _requestData['followRedirects' ] = value;
117
+ if (value == null ) {
118
+ _requestData.remove ('followRedirects' );
119
+ } else {
120
+ _requestData['followRedirects' ] = value;
121
+ }
77
122
}
78
123
124
+ bool ? get followRedirects => _requestData['followRedirects' ] as bool ? ;
125
+
79
126
/// The request headers where duplicate headers are represented using a list
80
127
/// of values.
81
128
///
@@ -85,7 +132,7 @@ final class HttpProfileRequestData {
85
132
/// // Foo: Bar
86
133
/// // Foo: Baz
87
134
///
88
- /// profile?.requestData.headersListValues({'Foo', ['Bar', 'Baz']});
135
+ /// profile?.requestData.headersListValues({'Foo': ['Bar', 'Baz']});
89
136
/// ```
90
137
set headersListValues (Map <String , List <String >>? value) {
91
138
_checkAndUpdate ();
@@ -105,7 +152,7 @@ final class HttpProfileRequestData {
105
152
/// // Foo: Bar
106
153
/// // Foo: Baz
107
154
///
108
- /// profile?.requestData.headersCommaValues({'Foo', 'Bar, Baz']});
155
+ /// profile?.requestData.headersCommaValues({'Foo': 'Bar, Baz']});
109
156
/// ```
110
157
set headersCommaValues (Map <String , String >? value) {
111
158
_checkAndUpdate ();
@@ -116,24 +163,81 @@ final class HttpProfileRequestData {
116
163
_requestData['headers' ] = splitHeaderValues (value);
117
164
}
118
165
166
+ /// An unmodifiable map representing the request headers. Duplicate headers
167
+ /// are represented using a list of values.
168
+ ///
169
+ /// For example, the map
170
+ ///
171
+ /// ```dart
172
+ /// {'Foo': ['Bar', 'Baz']});
173
+ /// ```
174
+ ///
175
+ /// represents the headers
176
+ ///
177
+ /// Foo: Bar
178
+ /// Foo: Baz
179
+ Map <String , List <String >>? get headers => _requestData['headers' ] == null
180
+ ? null
181
+ : UnmodifiableMapView (
182
+ _requestData['headers' ] as Map <String , List <String >>);
183
+
119
184
/// The maximum number of redirects allowed during the request.
120
- set maxRedirects (int value) {
185
+ set maxRedirects (int ? value) {
121
186
_checkAndUpdate ();
122
- _requestData['maxRedirects' ] = value;
187
+ if (value == null ) {
188
+ _requestData.remove ('maxRedirects' );
189
+ } else {
190
+ _requestData['maxRedirects' ] = value;
191
+ }
123
192
}
124
193
194
+ int ? get maxRedirects => _requestData['maxRedirects' ] as int ? ;
195
+
125
196
/// The requested persistent connection state.
126
- set persistentConnection (bool value) {
197
+ set persistentConnection (bool ? value) {
127
198
_checkAndUpdate ();
128
- _requestData['persistentConnection' ] = value;
199
+ if (value == null ) {
200
+ _requestData.remove ('persistentConnection' );
201
+ } else {
202
+ _requestData['persistentConnection' ] = value;
203
+ }
129
204
}
130
205
206
+ bool ? get persistentConnection =>
207
+ _requestData['persistentConnection' ] as bool ? ;
208
+
131
209
/// Proxy authentication details for the request.
132
- set proxyDetails (HttpProfileProxyData value) {
210
+ set proxyDetails (HttpProfileProxyData ? value) {
133
211
_checkAndUpdate ();
134
- _requestData['proxyDetails' ] = value._toJson ();
212
+ if (value == null ) {
213
+ _requestData.remove ('proxyDetails' );
214
+ } else {
215
+ _requestData['proxyDetails' ] = value._toJson ();
216
+ }
135
217
}
136
218
219
+ HttpProfileProxyData ? get proxyDetails => _requestData['proxyDetails' ] == null
220
+ ? null
221
+ : HttpProfileProxyData ._fromJson (
222
+ _requestData['proxyDetails' ] as Map <String , dynamic >,
223
+ );
224
+
225
+ /// The time at which the request was initiated.
226
+ DateTime get startTime => DateTime .fromMicrosecondsSinceEpoch (
227
+ _data['requestStartTimestamp' ] as int ,
228
+ );
229
+
230
+ /// The time when the request was fully sent.
231
+ DateTime ? get endTime => _data['requestEndTimestamp' ] == null
232
+ ? null
233
+ : DateTime .fromMicrosecondsSinceEpoch (
234
+ _data['requestEndTimestamp' ] as int ,
235
+ );
236
+
237
+ /// The error that the request failed with.
238
+ String ? get error =>
239
+ _requestData['error' ] == null ? null : _requestData['error' ] as String ;
240
+
137
241
HttpProfileRequestData ._(
138
242
this ._data,
139
243
this ._updated,
0 commit comments