Chromium Code Reviews| Index: pkg/shelf/lib/src/response.dart |
| diff --git a/pkg/shelf/lib/src/response.dart b/pkg/shelf/lib/src/response.dart |
| index c36c551a5a177ddcf6fae74d675e69af640b0e49..8284d1958770f0e49c2c62a70c4a3540981b07ca 100644 |
| --- a/pkg/shelf/lib/src/response.dart |
| +++ b/pkg/shelf/lib/src/response.dart |
| @@ -144,17 +144,20 @@ class Response extends Message { |
| /// |
| /// This indicates that the server is refusing to fulfill the request. |
| /// |
| - /// [body] is the response body. It may be either a [String], a |
| - /// [Stream<List<int>>], or `null` to indicate no body. If it's a [String], |
| - /// [encoding] is used to encode it to a [Stream<List<int>>]. It defaults to |
| - /// UTF-8. |
| + /// [body] is the response body. It may be either a [String] or a |
| + /// [Stream<List<int>>]. |
|
nweiz
2014/09/23 00:09:38
This should still include "or `null`".
kevmoo
2014/09/23 05:00:04
Done.
|
| + /// If it's a [String], [encoding] is used to encode it to a |
| + /// [Stream<List<int>>]. The default encoding is UTF-8. |
| + /// If it's `null` or not passed, a default error message is used. |
|
nweiz
2014/09/23 00:09:38
Nit: keep this text nicely line-wrapped.
kevmoo
2014/09/23 05:00:04
Done.
|
| /// |
| /// If [encoding] is passed, the "encoding" field of the Content-Type header |
| /// in [headers] will be set appropriately. If there is no existing |
| /// Content-Type header, it will be set to "application/octet-stream". |
| Response.forbidden(body, {Map<String, String> headers, |
| Encoding encoding, Map<String, Object> context}) |
| - : this(403, body: body, headers: headers, |
| + : this(403, |
| + headers: body == null ? _adjustErrorHeaders(headers) : headers, |
| + body: body == null ? 'Forbidden' : body, |
| context: context); |
| /// Constructs a 404 Not Found response. |
| @@ -162,17 +165,20 @@ class Response extends Message { |
| /// This indicates that the server didn't find any resource matching the |
| /// requested URI. |
| /// |
| - /// [body] is the response body. It may be either a [String], a |
| - /// [Stream<List<int>>], or `null` to indicate no body. If it's a [String], |
| - /// [encoding] is used to encode it to a [Stream<List<int>>]. It defaults to |
| - /// UTF-8. |
| + /// [body] is the response body. It may be either a [String] or a |
| + /// [Stream<List<int>>]. |
| + /// If it's a [String], [encoding] is used to encode it to a |
| + /// [Stream<List<int>>]. The default encoding is UTF-8. |
| + /// If it's `null` or not passed, a default error message is used. |
| /// |
| /// If [encoding] is passed, the "encoding" field of the Content-Type header |
| /// in [headers] will be set appropriately. If there is no existing |
| /// Content-Type header, it will be set to "application/octet-stream". |
| Response.notFound(body, {Map<String, String> headers, Encoding encoding, |
| Map<String, Object> context}) |
| - : this(404, body: body, headers: headers, |
| + : this(404, |
| + headers: body == null ? _adjustErrorHeaders(headers) : headers, |
| + body: body == null ? 'Not Found' : body, |
| context: context); |
| /// Constructs a 500 Internal Server Error response. |
| @@ -180,10 +186,11 @@ class Response extends Message { |
| /// This indicates that the server had an internal error that prevented it |
| /// from fulfilling the request. |
| /// |
| - /// [body] is the response body. It may be either a [String], a |
| - /// [Stream<List<int>>], or `null` to indicate no body. If it's `null` or not |
| - /// passed, a default error message is used. If it's a [String], [encoding] is |
| - /// used to encode it to a [Stream<List<int>>]. It defaults to UTF-8. |
| + /// [body] is the response body. It may be either a [String] or a |
| + /// [Stream<List<int>>]. |
| + /// If it's a [String], [encoding] is used to encode it to a |
| + /// [Stream<List<int>>]. The default encoding is UTF-8. |
| + /// If it's `null` or not passed, a default error message is used. |
| /// |
| /// If [encoding] is passed, the "encoding" field of the Content-Type header |
| /// in [headers] will be set appropriately. If there is no existing |
| @@ -191,7 +198,7 @@ class Response extends Message { |
| Response.internalServerError({body, Map<String, String> headers, |
| Encoding encoding, Map<String, Object> context}) |
| : this(500, |
| - headers: body == null ? _adjust500Headers(headers) : headers, |
| + headers: body == null ? _adjustErrorHeaders(headers) : headers, |
| body: body == null ? 'Internal Server Error' : body, |
| context: context); |
| @@ -200,9 +207,9 @@ class Response extends Message { |
| /// [statusCode] must be greater than or equal to 100. |
| /// |
| /// [body] is the response body. It may be either a [String], a |
| - /// [Stream<List<int>>], or `null` to indicate no body. If it's `null` or not |
| - /// passed, a default error message is used. If it's a [String], [encoding] is |
| - /// used to encode it to a [Stream<List<int>>]. It defaults to UTF-8. |
| + /// [Stream<List<int>>], or `null` to indicate no body. |
| + /// If it's a [String], [encoding] is used to encode it to a |
| + /// [Stream<List<int>>]. The default encoding is UTF-8. |
| /// |
| /// If [encoding] is passed, the "encoding" field of the Content-Type header |
| /// in [headers] will be set appropriately. If there is no existing |
| @@ -283,7 +290,7 @@ Map<String, String> _addHeader(Map<String, String> headers, String name, |
| /// |
| /// Returns a new map without modifying [headers]. This is used to add |
| /// content-type information when creating a 500 response with a default body. |
| -Map<String, String> _adjust500Headers(Map<String, String> headers) { |
| +Map<String, String> _adjustErrorHeaders(Map<String, String> headers) { |
| if (headers == null || headers['content-type'] == null) { |
| return _addHeader(headers, 'content-type', 'text/plain'); |
| } |