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 {
|
fn send_response(mut stream: TcpStream, status: u16, body: &str) -> UnitOrBoxedError {
|
||||||
let status_line = match status {
|
let status_line = match status {
|
||||||
200 => "HTTP/1.1 200 OK",
|
200 => "200 OK",
|
||||||
400 => "HTTP/1.1 400 BAD REQUEST",
|
400 => "400 BAD REQUEST",
|
||||||
404 => "HTTP/1.1 404 NOT FOUND",
|
404 => "404 NOT FOUND",
|
||||||
405 => "HTTP/1.1 405 METHOD NOT ALLOWED",
|
405 => "405 METHOD NOT ALLOWED",
|
||||||
_ => "HTTP/1.1 500 INTERNAL SERVER ERROR",
|
_ => "500 INTERNAL SERVER ERROR",
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = format!(
|
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,
|
status_line,
|
||||||
body.len(),
|
body.len(),
|
||||||
body
|
body
|
||||||
|
|
Loading…
Reference in a new issue