1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use super::{body::Body, header::Header, status::Status};
/// An HTTP response.
#[derive(Debug)]
pub struct Response {
status: Status,
headers: Header,
body: Body,
}
impl Response {
/// Creates a new HTTP response.
pub fn new(status: impl Into<Status>, headers: Header, body: impl Into<Body>) -> Self {
Self {
status: status.into(),
headers,
body: body.into(),
}
}
/// Returns the response status.
pub fn status(&self) -> &Status {
&self.status
}
/// Returns the response headers.
pub fn headers(&self) -> &Header {
&self.headers
}
/// Returns the response body.
pub fn body(&self) -> &Body {
&self.body
}
/// Returns a mutable reference to the response status.
pub fn status_mut(&mut self) -> &mut Status {
&mut self.status
}
/// Returns a mutable reference to the response headers.
pub fn headers_mut(&mut self) -> &mut Header {
&mut self.headers
}
/// Returns a mutable reference to the response body.
pub fn body_mut(&mut self) -> &mut Body {
&mut self.body
}
/// Consumes the response and returns its body.
pub fn into_body(self) -> Body {
self.body
}
/// Consumes the response and returns its components.
pub fn into_parts(self) -> (Status, Header, Body) {
(self.status, self.headers, self.body)
}
}