Skip to content

Commit 5c7b451

Browse files
committed
Return an emptyStream with null body
1 parent 928d7a1 commit 5c7b451

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/src/body.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class Body {
2929
/// determined efficiently.
3030
final int contentLength;
3131

32+
/// An empty stream for use with empty bodies.
33+
static const _emptyStream = const Stream.empty();
34+
3235
Body._(this._stream, this.encoding, this.contentLength);
3336

3437
/// Converts [body] to a byte stream and wraps it in a [Body].
@@ -38,8 +41,9 @@ class Body {
3841
/// used to convert it to a [Stream<List<int>>].
3942
factory Body(body, [Encoding encoding]) {
4043
if (body is Body) return body;
41-
if (body == null)
42-
return new Body._(new Stream.fromIterable([]), encoding, 0);
44+
if (body == null) {
45+
return new Body._(_emptyStream, encoding, 0);
46+
}
4347

4448
Stream<List<int>> stream;
4549
int contentLength;

0 commit comments

Comments
 (0)