sapper/
response.rs

1use hyper::status::StatusCode;
2use hyper::header::Headers;
3
4/// Sapper response struct
5pub struct SapperResponse {
6    status: StatusCode,
7    headers: Headers,
8    body: Option<Vec<u8>>,
9}
10
11
12impl SapperResponse {
13    pub fn new() -> SapperResponse {
14        SapperResponse {
15            status: StatusCode::Ok,
16            headers: Headers::new(),
17            body: None
18        }
19    }
20    
21    /// get response status
22    pub fn status(&self) -> StatusCode {
23        self.status
24    }
25    
26    /// set response status
27    pub fn set_status(&mut self, status: StatusCode) {
28        self.status = status;
29    }
30    
31    
32    /// get response headers ref
33    pub fn headers(&self) -> &Headers {
34        &self.headers
35    }
36    
37    /// get response headers mut ref
38    pub fn headers_mut(&mut self) -> &mut Headers {
39        &mut self.headers
40    }
41    
42    /// get response body mut ref
43    pub fn body(&self) -> &Option<Vec<u8>>{
44        &self.body
45    }
46    
47    /// write string to body
48    pub fn write_body(&mut self, body: String) {
49        self.body = Some(body.as_bytes().to_vec())
50    }
51    
52    /// write raw u8 vec to body
53    pub fn write_raw_body(&mut self, body: Vec<u8>) {
54        self.body = Some(body)
55    }
56    
57}
58