Chromium Code Reviews| Index: dart/pkg/shelf/lib/src/message.dart |
| diff --git a/dart/pkg/shelf/lib/src/message.dart b/dart/pkg/shelf/lib/src/message.dart |
| index 1522e1301aac2ca2af36caec47af853ddbec111f..794f9ccdc48a4ef241ce11834f24d38478276850 100644 |
| --- a/dart/pkg/shelf/lib/src/message.dart |
| +++ b/dart/pkg/shelf/lib/src/message.dart |
| @@ -37,6 +37,12 @@ abstract class Message { |
| /// This can be read via [read] or [readAsString]. |
| final Stream<List<int>> _body; |
| + /// This boolean indicates whether [_body] has been read. |
| + /// |
| + /// After calling [read], or [readAsString] (which internally calls [read]), |
| + /// this will be `true`. |
| + bool _bodyWasRead = false; |
| + |
| /// Creates a new [Message]. |
| /// |
| /// If [headers] is `null`, it is treated as empty. |
| @@ -98,7 +104,14 @@ abstract class Message { |
| /// Returns a [Stream] representing the body. |
| /// |
| /// Can only be called once. |
| - Stream<List<int>> read() => _body; |
| + Stream<List<int>> read() { |
| + if (_bodyWasRead) { |
| + throw new StateError("The 'read()' method can only be called once on a " |
|
kevmoo
2014/06/20 15:42:25
Change to "The 'read' method can only be called on
kustermann
2014/06/23 08:31:03
Done.
|
| + "shelf.Request/shelf.Response object."); |
| + } |
| + _bodyWasRead = true; |
| + return _body; |
| + } |
| /// Returns a [Future] containing the body as a String. |
| /// |