File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1+ ## 1.4.0-dev
2+
3+ * Add Response.unauthorized() constructor
4+
15## 1.3.2
26
37* ` shelf_io.dart `
Original file line number Diff line number Diff line change @@ -180,6 +180,25 @@ class Response extends Message {
180180 encoding: encoding,
181181 );
182182
183+ /// Constructs a 401 Unauthorized response.
184+ ///
185+ /// This indicates indicates that the client request has not been completed
186+ /// because it lacks valid authentication credentials.
187+ ///
188+ /// {@macro shelf_response_body_and_encoding_param}
189+ Response .unauthorized (
190+ Object ? body, {
191+ Map <String , /* String | List<String> */ Object >? headers,
192+ Encoding ? encoding,
193+ Map <String , Object >? context,
194+ }) : this (
195+ 401 ,
196+ headers: body == null ? _adjustErrorHeaders (headers) : headers,
197+ body: body ?? 'Unauthorized' ,
198+ context: context,
199+ encoding: encoding,
200+ );
201+
183202 /// Constructs a 403 Forbidden response.
184203 ///
185204 /// This indicates that the server is refusing to fulfill the request.
Original file line number Diff line number Diff line change 11name : shelf
2- version : 1.3.2
2+ version : 1.4.0-dev
33description : >
44 A model for web server middleware that encourages composition and easy reuse.
55repository : https://github.com/dart-lang/shelf/tree/master/pkgs/shelf
Original file line number Diff line number Diff line change @@ -106,6 +106,15 @@ void main() {
106106 });
107107 });
108108
109+ group ('Response.unauthorized:' , () {
110+ test ('sets body' , () {
111+ var response = Response .unauthorized ('request unauthorized' );
112+ expect (
113+ response.readAsString (), completion (equals ('request unauthorized' )));
114+ expect (response.statusCode, 401 );
115+ });
116+ });
117+
109118 group ('Response redirect' , () {
110119 test ('sets the location header for a String' , () {
111120 var response = Response .found ('/foo' );
You can’t perform that action at this time.
0 commit comments