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