summaryrefslogtreecommitdiff
path: root/src/server/response.rs
diff options
context:
space:
mode:
authorJan Wolff <janw@mailbox.org>2020-05-16 11:03:48 +0200
committerJan Wolff <janw@mailbox.org>2020-05-16 11:03:48 +0200
commit769affa1b651f3591b5d9c482b6fd5b142c7f3d6 (patch)
tree9df2734b8ae35adf650a7bd16850a8f014a8fa2a /src/server/response.rs
parentd5d223389698b361ed362721ee4f3a7ab8a110cb (diff)
architecture changes
Diffstat (limited to 'src/server/response.rs')
-rw-r--r--src/server/response.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/server/response.rs b/src/server/response.rs
index f2df722..36d5d15 100644
--- a/src/server/response.rs
+++ b/src/server/response.rs
@@ -2,12 +2,12 @@ use std::vec::Vec;
#[derive(Copy, Clone)]
pub enum Status {
- Input = 1,
- Success = 2,
- Redirect = 3,
- TemporaryFailure = 4,
- PermanentFailure = 5,
- ClientCertificateRequired = 6,
+ Input = 10,
+ Success = 20,
+ Redirect = 30,
+ TemporaryFailure = 40,
+ PermanentFailure = 50,
+ ClientCertificateRequired = 60,
}
pub struct Header {
@@ -22,28 +22,27 @@ pub struct Response {
impl Header {
pub fn new(status: Status, meta: &str) -> Header {
- Header{
+ Header {
status: status,
meta: meta.to_string(),
}
}
pub fn format(&self) -> String {
- let status: u8 = self.status as u8;
- return format!("{} {}\r\n", status * 10, self.meta)
+ format!("{} {}\r\n", self.status as u8, self.meta)
}
}
impl Response {
pub fn new(header: Header, data: Vec<u8>) -> Response {
- Response{
+ Response {
header: header,
data: data,
}
}
pub fn new_empty(header: Header) -> Response {
- Response{
+ Response {
header: header,
data: Vec::new(),
}
@@ -56,11 +55,23 @@ impl Response {
}
}
-pub fn invalid_protocol () -> Response {
- Response::new_empty(
- Header::new(
- Status::PermanentFailure,
- "this protocol is not supported"
- ),
- )
+pub fn invalid_protocol() -> Response {
+ Response::new_empty(Header::new(
+ Status::PermanentFailure,
+ "this protocol is not supported",
+ ))
+}
+
+pub fn not_understood() -> Response {
+ Response::new_empty(Header::new(
+ Status::PermanentFailure,
+ "request not understood",
+ ))
+}
+
+pub fn internal_error() -> Response {
+ Response::new_empty(Header::new(
+ Status::PermanentFailure,
+ "internal server error",
+ ))
}