Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkgs/http_profile/lib/src/http_client_request_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ final class HttpClientRequestProfile {
responseData = HttpProfileResponseData._(_data, _updated);
_data['requestBodyBytes'] = <int>[];
requestData._body.stream.listen(
(final bytes) => (_data['requestBodyBytes'] as List<int>).addAll(bytes),
);
(final bytes) => (_data['requestBodyBytes'] as List<int>).addAll(bytes),
onError: (e) {});
_data['responseBodyBytes'] = <int>[];
responseData._body.stream.listen(
(final bytes) => (_data['responseBodyBytes'] as List<int>).addAll(bytes),
);
(final bytes) =>
(_data['responseBodyBytes'] as List<int>).addAll(bytes),
onError: (e) {});
// This entry is needed to support the updatedSince parameter of
// ext.dart.io.getHttpProfile.
_updated();
Expand Down
3 changes: 3 additions & 0 deletions pkgs/http_profile/lib/src/http_profile_request_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ final class HttpProfileRequestData {
_data['requestData'] as Map<String, dynamic>;

/// A sink that can be used to record the body of the request.
///
/// Errors added to [bodySink] (for example with [StreamSink.addError]) are
/// ignored.
StreamSink<List<int>> get bodySink => _body.sink;

/// The body of the request represented as an unmodifiable list of bytes.
Expand Down
3 changes: 3 additions & 0 deletions pkgs/http_profile/lib/src/http_profile_response_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ final class HttpProfileResponseData {
.map(HttpProfileRedirectData._fromJson));

/// A sink that can be used to record the body of the response.
///
/// Errors added to [bodySink] (for example with [StreamSink.addError]) are
/// ignored.
StreamSink<List<int>> get bodySink => _body.sink;

/// The body of the response represented as an unmodifiable list of bytes.
Expand Down
6 changes: 4 additions & 2 deletions pkgs/http_profile/test/http_profile_request_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,11 @@ void main() {
expect(profile.requestData.bodyBytes, isEmpty);

profile.requestData.bodySink.add([1, 2, 3]);
profile.requestData.bodySink.addError('this is an error');
profile.requestData.bodySink.add([4, 5]);
await profile.requestData.close();

expect(requestBodyBytes, [1, 2, 3]);
expect(profile.requestData.bodyBytes, [1, 2, 3]);
expect(requestBodyBytes, [1, 2, 3, 4, 5]);
expect(profile.requestData.bodyBytes, [1, 2, 3, 4, 5]);
});
}
6 changes: 4 additions & 2 deletions pkgs/http_profile/test/http_profile_response_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,11 @@ void main() {
expect(profile.responseData.bodyBytes, isEmpty);

profile.responseData.bodySink.add([1, 2, 3]);
profile.responseData.bodySink.addError('this is an error');
profile.responseData.bodySink.add([4, 5]);
await profile.responseData.close();

expect(responseBodyBytes, [1, 2, 3]);
expect(profile.responseData.bodyBytes, [1, 2, 3]);
expect(responseBodyBytes, [1, 2, 3, 4, 5]);
expect(profile.responseData.bodyBytes, [1, 2, 3, 4, 5]);
});
}