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
61
62
63
64
65
use std::fmt;
use header;
use http::{self, RawStatus, Body};
use status;
use version;
pub fn new(incoming: http::ResponseHead, body: Option<Body>) -> Response {
trace!("Response::new");
let status = status::StatusCode::from_u16(incoming.subject.0);
debug!("version={:?}, status={:?}", incoming.version, status);
debug!("headers={:?}", incoming.headers);
Response {
status: status,
version: incoming.version,
headers: incoming.headers,
status_raw: incoming.subject,
body: body,
}
}
pub struct Response {
status: status::StatusCode,
headers: header::Headers,
version: version::HttpVersion,
status_raw: RawStatus,
body: Option<Body>,
}
impl Response {
#[inline]
pub fn headers(&self) -> &header::Headers { &self.headers }
#[inline]
pub fn status(&self) -> &status::StatusCode { &self.status }
#[inline]
pub fn status_raw(&self) -> &RawStatus { &self.status_raw }
#[inline]
pub fn version(&self) -> &version::HttpVersion { &self.version }
#[inline]
pub fn body(mut self) -> Body {
self.body.take().unwrap_or(Body::empty())
}
}
impl fmt::Debug for Response {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Response")
.field("status", &self.status)
.field("version", &self.version)
.field("headers", &self.headers)
.finish()
}
}