Skip to content

Commit

Permalink
Ignore errors added to bodySinks
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Mar 27, 2024
1 parent 280d361 commit 2e83488
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
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]);
});
}

0 comments on commit 2e83488

Please sign in to comment.