@@ -11,10 +11,8 @@ final class HttpProfileRequestEvent {
11
11
final int _timestamp;
12
12
final String _name;
13
13
14
- /// [timestamp] should be the time at which the event occurred, as a
15
- /// microsecond value on the monotonic clock used by the [Timeline] .
16
- HttpProfileRequestEvent ({required int timestamp, required String name})
17
- : _timestamp = timestamp,
14
+ HttpProfileRequestEvent ({required DateTime timestamp, required String name})
15
+ : _timestamp = timestamp.microsecondsSinceEpoch,
18
16
_name = name;
19
17
20
18
Map <String , dynamic > _toJson () => < String , dynamic > {
@@ -30,9 +28,12 @@ final class HttpProfileProxyData {
30
28
final bool ? _isDirect;
31
29
final int ? _port;
32
30
33
- HttpProfileProxyData (
34
- {String ? host, String ? username, bool ? isDirect, int ? port})
35
- : _host = host,
31
+ HttpProfileProxyData ({
32
+ String ? host,
33
+ String ? username,
34
+ bool ? isDirect,
35
+ int ? port,
36
+ }) : _host = host,
36
37
_username = username,
37
38
_isDirect = isDirect,
38
39
_port = port;
@@ -45,15 +46,48 @@ final class HttpProfileProxyData {
45
46
};
46
47
}
47
48
49
+ /// Describes a redirect that an HTTP connection went through.
50
+ class HttpProfileRedirectData {
51
+ int _statusCode;
52
+ String _method;
53
+ String _location;
54
+
55
+ HttpProfileRedirectData ({
56
+ required int statusCode,
57
+ required String method,
58
+ required String location,
59
+ }) : _statusCode = statusCode,
60
+ _method = method,
61
+ _location = location;
62
+
63
+ Map <String , dynamic > _toJson () => < String , dynamic > {
64
+ 'statusCode' : _statusCode,
65
+ 'method' : _method,
66
+ 'location' : _location,
67
+ };
68
+ }
69
+
48
70
/// Describes details about an HTTP request.
49
71
final class HttpProfileRequestData {
50
72
final Map <String , dynamic > _data;
51
73
52
74
final void Function () _updated;
53
75
54
- /// The elements of [connectionInfo] can either be [String] s or [int] s.
76
+ /// Information about the networking connection used in the HTTP request.
77
+ ///
78
+ /// This information is meant to be used for debugging.
79
+ ///
80
+ /// It can contain any arbitrary data as long as the values are of type
81
+ /// [String] or [int] . For example:
82
+ /// { 'localPort': 1285, 'remotePort': 443, 'connectionPoolId': '21x23' }
55
83
set connectionInfo (Map <String , dynamic /*String|int*/ > value) {
56
- _data['connectionInfo' ] = value;
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
+ }
90
+ _data['connectionInfo' ] = {...value};
57
91
_updated ();
58
92
}
59
93
@@ -64,30 +98,29 @@ final class HttpProfileRequestData {
64
98
}
65
99
66
100
/// The cookies presented to the server (in the 'cookie' header).
67
- set cookies (List <String > value) {
68
- _data['cookies' ] = value;
101
+ set cookies (List <Cookie > value) {
102
+ _data['cookies' ] = [ for ( final cookie in value) cookie. toString ()] ;
69
103
_updated ();
70
104
}
71
105
72
- /// The error associated with the failed request.
106
+ /// The error associated with a failed request.
73
107
set error (String value) {
74
108
_data['error' ] = value;
75
109
_updated ();
76
110
}
77
111
78
- /// Whether redirects were followed automatically .
112
+ /// Whether automatic redirect following was enabled for the request .
79
113
set followRedirects (bool value) {
80
114
_data['followRedirects' ] = value;
81
115
_updated ();
82
116
}
83
117
84
118
set headers (Map <String , List <String >> value) {
85
- _data['headers' ] = value;
119
+ _data['headers' ] = {... value} ;
86
120
_updated ();
87
121
}
88
122
89
- /// If [followRedirects] is true, this is the maximum number of redirects that
90
- /// were followed.
123
+ /// The maximum of redirects allowed during the request.
91
124
set maxRedirects (int value) {
92
125
_data['maxRedirects' ] = value;
93
126
_updated ();
@@ -105,8 +138,10 @@ final class HttpProfileRequestData {
105
138
_updated ();
106
139
}
107
140
108
- HttpProfileRequestData ._(
109
- Map <String , dynamic > this ._data, void Function () this ._updated);
141
+ const HttpProfileRequestData ._(
142
+ Map <String , dynamic > this ._data,
143
+ void Function () this ._updated,
144
+ );
110
145
}
111
146
112
147
/// Describes details about a response to an HTTP request.
@@ -115,27 +150,38 @@ final class HttpProfileResponseData {
115
150
116
151
final void Function () _updated;
117
152
118
- /// Records a redirect that the connection went through. The elements of
119
- /// [redirect] can either be [String] s or [int] s.
120
- void addRedirect (Map <String , dynamic /*String|int*/ > redirect) {
121
- _data['redirects' ].add (redirect);
153
+ /// Records a redirect that the connection went through.
154
+ void addRedirect (HttpProfileRedirectData redirect) {
155
+ _data['redirects' ].add (redirect._toJson ());
122
156
_updated ();
123
157
}
124
158
125
159
/// The cookies set by the server (from the 'set-cookie' header).
126
- set cookies (List <String > value) {
127
- _data['cookies' ] = value;
160
+ set cookies (List <Cookie > value) {
161
+ _data['cookies' ] = [ for ( final cookie in value) cookie. toString ()] ;
128
162
_updated ();
129
163
}
130
164
131
- /// The elements of [connectionInfo] can either be [String] s or [int] s.
165
+ /// Information about the networking connection used in the HTTP response.
166
+ ///
167
+ /// This information is meant to be used for debugging.
168
+ ///
169
+ /// It can contain any arbitrary data as long as the values are of type
170
+ /// [String] or [int] . For example:
171
+ /// { 'localPort': 1285, 'remotePort': 443, 'connectionPoolId': '21x23' }
132
172
set connectionInfo (Map <String , dynamic /*String|int*/ > value) {
133
- _data['connectionInfo' ] = value;
173
+ for (final v in value.values) {
174
+ if (! (v is String || v is int )) {
175
+ throw ArgumentError (
176
+ "The values in connectionInfo must be of type String or int." );
177
+ }
178
+ }
179
+ _data['connectionInfo' ] = {...value};
134
180
_updated ();
135
181
}
136
182
137
183
set headers (Map <String , List <String >> value) {
138
- _data['headers' ] = value;
184
+ _data['headers' ] = {... value} ;
139
185
_updated ();
140
186
}
141
187
@@ -144,8 +190,8 @@ final class HttpProfileResponseData {
144
190
// This specifies whether the response bytes were compressed when they were
145
191
// received across the wire and whether callers will receive compressed or
146
192
// uncompressed bytes when they listen to the response body byte stream.
147
- set compressionState (String value) {
148
- _data['compressionState' ] = value;
193
+ set compressionState (HttpClientResponseCompressionState value) {
194
+ _data['compressionState' ] = value.name ;
149
195
_updated ();
150
196
}
151
197
@@ -177,29 +223,29 @@ final class HttpProfileResponseData {
177
223
_updated ();
178
224
}
179
225
180
- /// The time at which the initial response was received, as a microsecond
181
- /// value on the monotonic clock used by the [Timeline] .
182
- set startTime (int value) {
183
- _data['startTime' ] = value;
226
+ /// The time at which the initial response was received.
227
+ set startTime (DateTime value) {
228
+ _data['startTime' ] = value.microsecondsSinceEpoch;
184
229
_updated ();
185
230
}
186
231
187
- /// The time at which the response was completed, as a microsecond value on
188
- /// the monotonic clock used by the [Timeline] . Note that DevTools will not
232
+ /// The time at which the response was completed. Note that DevTools will not
189
233
/// consider the request to be complete until [endTime] is non-null.
190
- set endTime (int value) {
191
- _data['endTime' ] = value;
234
+ set endTime (DateTime value) {
235
+ _data['endTime' ] = value.microsecondsSinceEpoch ;
192
236
_updated ();
193
237
}
194
238
195
- /// The error associated with the failed request.
239
+ /// The error associated with a failed request.
196
240
set error (String value) {
197
241
_data['error' ] = value;
198
242
_updated ();
199
243
}
200
244
201
245
HttpProfileResponseData ._(
202
- Map <String , dynamic > this ._data, void Function () this ._updated) {
246
+ Map <String , dynamic > this ._data,
247
+ void Function () this ._updated,
248
+ ) {
203
249
_data['redirects' ] = < Map <String , dynamic >> [];
204
250
}
205
251
}
@@ -242,29 +288,25 @@ final class HttpClientRequestProfile {
242
288
/// Usage example:
243
289
///
244
290
/// ```dart
245
- /// profile.addEvent(HttpProfileRequestEvent(Timeline .now, "Connection Established");
246
- /// profile.addEvent(HttpProfileRequestEvent(Timeline .now, "Remote Disconnected");
291
+ /// profile.addEvent(HttpProfileRequestEvent(DateTime .now() , "Connection Established");
292
+ /// profile.addEvent(HttpProfileRequestEvent(DateTime .now() , "Remote Disconnected");
247
293
/// ```
248
294
void addEvent (HttpProfileRequestEvent event) {
249
295
_data['events' ].add (event._toJson ());
250
296
_updated ();
251
297
}
252
298
253
- /// The time at which the request was initiated, as a microsecond value on the
254
- /// monotonic clock used by the [Timeline] .
255
- int ? get requestStartTimestamp => _data['requestStartTimestamp' ] as int ? ;
256
- set requestStartTimestamp (int ? value) {
257
- _data['requestStartTimestamp' ] = value;
299
+ /// The time at which the request was initiated.
300
+ set requestStartTimestamp (DateTime value) {
301
+ _data['requestStartTimestamp' ] = value.microsecondsSinceEpoch;
258
302
_updated ();
259
303
}
260
304
261
- /// The time at which the request was completed, as a microsecond value on the
262
- /// monotonic clock used by the [Timeline] . Note that DevTools will not
305
+ /// The time at which the request was completed. Note that DevTools will not
263
306
/// consider the request to be complete until [requestEndTimestamp] is
264
307
/// non-null.
265
- int ? get requestEndTimestamp => _data['requestEndTimestamp' ] as int ? ;
266
- set requestEndTimestamp (int ? value) {
267
- _data['requestEndTimestamp' ] = value;
308
+ set requestEndTimestamp (DateTime value) {
309
+ _data['requestEndTimestamp' ] = value.microsecondsSinceEpoch;
268
310
_updated ();
269
311
}
270
312
0 commit comments