Skip to content

Commit 56640e3

Browse files
authored
feat(dart_frog): add Response.stream (#562)
1 parent b283bba commit 56640e3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/dart_frog/lib/src/response.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ class Response {
1919
),
2020
);
2121

22+
/// Create a [Response] with a stream of bytes.
23+
Response.stream({
24+
int statusCode = 200,
25+
Stream<List<int>>? body,
26+
Map<String, Object>? headers,
27+
}) : this._(
28+
shelf.Response(
29+
statusCode,
30+
body: body,
31+
headers: headers,
32+
),
33+
);
34+
2235
/// Create a [Response] with a byte array body.
2336
Response.bytes({
2437
int statusCode = 200,

packages/dart_frog/test/src/response_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ void main() {
100100
});
101101
});
102102

103+
group('stream', () {
104+
test('has correct body', () {
105+
final bytes = utf8.encode('hello');
106+
final stream = Stream.value(bytes);
107+
final response = Response.stream(body: stream);
108+
expect(response.bytes(), emits(equals(bytes)));
109+
});
110+
});
111+
103112
group('formData', () {
104113
final contentTypeFormUrlEncoded = {
105114
HttpHeaders.contentTypeHeader: formUrlEncodedContentType.mimeType

0 commit comments

Comments
 (0)