Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: dart/pkg/shelf/lib/src/message.dart

Issue 342323004: Throw a StateError if read()/readAsString() is called multiple times (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/pkg/shelf/test/message_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..514eb48569859522842892ea026fe983dcd0ca49 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 "
+ "shelf.Request/shelf.Response object.");
+ }
+ _bodyWasRead = true;
+ return _body;
+ }
/// Returns a [Future] containing the body as a String.
///
« no previous file with comments | « no previous file | dart/pkg/shelf/test/message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698