Index: pkg/http/lib/src/base_response.dart |
diff --git a/pkg/http/lib/src/base_response.dart b/pkg/http/lib/src/base_response.dart |
index df0edb4e34c4dcb4b5e9ef15ae6a2c2214e0c95b..f2225962eb3ac58ee4f7dac7f336d5a853987268 100644 |
--- a/pkg/http/lib/src/base_response.dart |
+++ b/pkg/http/lib/src/base_response.dart |
@@ -20,8 +20,9 @@ abstract class BaseResponse { |
/// The reason phrase associated with the status code. |
final String reasonPhrase; |
- /// The size of the response body, in bytes. If the size of the request is not |
- /// known in advance, this is -1. |
+ /// The size of the response body, in bytes. |
+ /// |
+ /// If the size of the request is not known in advance, this is `null`. |
final int contentLength; |
// TODO(nweiz): automatically parse cookies from headers |
@@ -39,10 +40,16 @@ abstract class BaseResponse { |
/// Creates a new HTTP response. |
BaseResponse( |
this.statusCode, |
- this.contentLength, |
- {this.request, |
+ {this.contentLength, |
+ this.request, |
this.headers: const {}, |
this.isRedirect: false, |
this.persistentConnection: true, |
- this.reasonPhrase}); |
+ this.reasonPhrase}) { |
+ if (statusCode < 100) { |
+ throw new ArgumentError("Invalid status code $statusCode."); |
+ } else if (contentLength != null && contentLength < 0) { |
+ throw new ArgumentError("Invalid content length $contentLength."); |
+ } |
+ } |
} |