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
|
use std::vec;
#[derive(Copy, Clone)]
pub enum Status {
Input = 1,
Success = 2,
Redirect = 3,
TemporaryFailure = 4,
PermanentFailure = 5,
ClientCertificateRequired = 6,
}
pub struct Header {
status: Status,
meta: String,
}
pub struct Response {
header: Header,
data: std::vec::Vec<u8>,
}
impl Header {
pub fn new(status: Status, meta: String) -> Header {
return Header{
status: status,
meta: meta,
}
}
pub fn format(&self) -> String {
let status: u8 = self.status as u8;
return format!("{} {}\r\n", status * 10, self.meta)
}
}
impl Response {
pub fn new(header: Header, data: std::vec::Vec<u8>) -> Response {
return Response{
header: header,
data: data,
}
}
pub fn format(&self) -> std::vec::Vec<u8> {
let mut resp: std::vec::Vec<u8> = self.header.format().as_bytes().to_vec();
resp.extend(&self.data);
return resp;
}
}
|