Skip to content

Commit d02c24e

Browse files
committed
Provide Response::<Fresh>::deconstruct to deconstruct a Response.
This allows downstream frameworks by-value access to these fields, letting them create their own Response abstractions out of hyper's Response.
1 parent e32845c commit d02c24e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/server/response.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ impl<W: WriteStatus> Response<W> {
4444

4545
/// The headers of this response.
4646
pub fn headers(&self) -> &header::Headers { &self.headers }
47+
48+
/// Construct a Response from its constituent parts.
49+
pub fn construct(version: version::HttpVersion,
50+
body: BufferedWriter<TcpStream>,
51+
status: status::StatusCode,
52+
headers: header::Headers) -> Response<Fresh> {
53+
Response {
54+
status: status,
55+
version: version,
56+
body: body,
57+
headers: headers
58+
}
59+
}
4760
}
4861

4962
impl Response<Fresh> {
@@ -89,6 +102,11 @@ impl Response<Fresh> {
89102

90103
/// Get a mutable reference to the Headers.
91104
pub fn headers_mut(&mut self) -> &mut header::Headers { &mut self.headers }
105+
106+
/// Deconstruct this Response into its constituent parts.
107+
pub fn deconstruct(self) -> (version::HttpVersion, BufferedWriter<TcpStream>, status::StatusCode, header::Headers) {
108+
(self.version, self.body, self.status, self.headers)
109+
}
92110
}
93111

94112
impl Response<Streaming> {

0 commit comments

Comments
 (0)