refactor: dry'd HTTP/1.1
This commit is contained in:
parent
8d8cfe33fa
commit
6744b6dee1
1 changed files with 6 additions and 6 deletions
|
@ -24,15 +24,15 @@ pub type UnitOrBoxedError = Result<(), Box<dyn Error>>;
|
|||
|
||||
fn send_response(mut stream: TcpStream, status: u16, body: &str) -> UnitOrBoxedError {
|
||||
let status_line = match status {
|
||||
200 => "HTTP/1.1 200 OK",
|
||||
400 => "HTTP/1.1 400 BAD REQUEST",
|
||||
404 => "HTTP/1.1 404 NOT FOUND",
|
||||
405 => "HTTP/1.1 405 METHOD NOT ALLOWED",
|
||||
_ => "HTTP/1.1 500 INTERNAL SERVER ERROR",
|
||||
200 => "200 OK",
|
||||
400 => "400 BAD REQUEST",
|
||||
404 => "404 NOT FOUND",
|
||||
405 => "405 METHOD NOT ALLOWED",
|
||||
_ => "500 INTERNAL SERVER ERROR",
|
||||
};
|
||||
|
||||
let response = format!(
|
||||
"{}\r\nContent-Length: {}\r\nServer: luciders/0.1.0\r\n\r\n{}",
|
||||
"{}\r\nContent-Length: {}\r\nServer: luciders/0.1.0\r\n\r\nHTTP/1.1 {}",
|
||||
status_line,
|
||||
body.len(),
|
||||
body
|
||||
|
|
Loading…
Reference in a new issue