pkg/shelf Include default bodies for 'Not Found' and 'Forbidden' Response

Also fixed documentation of Response constructors

R=nweiz@google.com

Review URL: https://codereview.chromium.org//596573002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/shelf@40607 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd7375d..d99158d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,11 @@
 ## 0.5.5
 
-* Updated `README` links to point to latest docs on `www.dartdocs.org`. 
+* Added default body text for `Response.forbidden` and `Response.notFound` if
+null is provided.
+
+* Clarified documentation on a number of `Response` constructors.
+
+* Updated `README` links to point to latest docs on `www.dartdocs.org`.
 
 ## 0.5.4+3
 
diff --git a/lib/src/response.dart b/lib/src/response.dart
index c36c551..f95fdb7 100644
--- a/lib/src/response.dart
+++ b/lib/src/response.dart
@@ -144,17 +144,19 @@
   ///
   /// 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 a [String], a [Stream<List<int>>],
+  /// or `null`. 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.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 +164,19 @@
   /// 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 a [String], a [Stream<List<int>>],
+  /// or `null`. 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 +184,10 @@
   /// 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 a [String], a [Stream<List<int>>],
+  /// or `null`. 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 +195,7 @@
   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 +204,9 @@
   /// [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 +287,7 @@
 ///
 /// 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');
   }
diff --git a/pubspec.yaml b/pubspec.yaml
index f5b7d9f..d4b6c09 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: shelf
-version: 0.5.5-dev
+version: 0.5.5
 author: Dart Team <misc@dartlang.org>
 description: Web Server Middleware for Dart
 homepage: http://www.dartlang.org