@@ -11,10 +11,20 @@ import 'utils.dart';
11
11
12
12
/// An HTTP response where the entire response body is known in advance.
13
13
class Response extends Message {
14
+ /// The location of the requested resource.
15
+ ///
16
+ /// The value takes into account any redirects that occurred during the
17
+ /// request.
18
+ final Uri location;
19
+
14
20
/// The status code of the response.
15
21
final int statusCode;
16
22
17
- /// Creates a new HTTP response with the given [statusCode] .
23
+ /// The reason phrase associated with the status code.
24
+ final String reasonPhrase;
25
+
26
+ /// Creates a new HTTP response for a resource at the [location] , which can
27
+ /// be a [Uri] or a [String] , with the given [statusCode] .
18
28
///
19
29
/// [body] is the request body. It may be either a [String] , a [List<int>] , a
20
30
/// [Stream<List<int>>] , or `null` to indicate no body. If it's a [String] ,
@@ -26,11 +36,20 @@ class Response extends Message {
26
36
///
27
37
/// Extra [context] can be used to pass information between outer middleware
28
38
/// and handlers.
29
- Response (this .statusCode,
30
- {body,
39
+ Response (location, int statusCode,
40
+ {String reasonPhrase,
41
+ body,
31
42
Encoding encoding,
32
43
Map <String , String > headers,
33
44
Map <String , Object > context})
45
+ : this ._(getUrl (location), statusCode, reasonPhrase ?? '' ,
46
+ body, encoding, headers, context);
47
+
48
+ Response ._(this .location, this .statusCode, this .reasonPhrase,
49
+ body,
50
+ Encoding encoding,
51
+ Map <String , String > headers,
52
+ Map <String , Object > context)
34
53
: super (body, encoding: encoding, headers: headers, context: context);
35
54
36
55
/// Creates a new [Response] by copying existing values and applying specified
@@ -55,10 +74,14 @@ class Response extends Message {
55
74
var updatedHeaders = updateMap (this .headers, headers);
56
75
var updatedContext = updateMap (this .context, context);
57
76
58
- return new Response (this .statusCode,
59
- body: body ?? getBody (this ),
60
- headers: updatedHeaders,
61
- context: updatedContext);
77
+ return new Response ._(
78
+ this .location,
79
+ this .statusCode,
80
+ this .reasonPhrase,
81
+ body ?? getBody (this ),
82
+ this .encoding,
83
+ updatedHeaders,
84
+ updatedContext);
62
85
}
63
86
64
87
/// The date and time after which the response's data should be considered
0 commit comments