diff --git a/src/builder.rs b/src/builder.rs index 2734394..b316eb2 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -42,10 +42,6 @@ impl ServerBuilder { } fn update_ip_filter_state(&mut self) { - if self.config.private_ips || !self.config.ips.is_empty() { - self.config.ip_filter = true; - } else { - self.config.ip_filter = false; - } + self.config.ip_filter = self.config.private_ips || !self.config.ips.is_empty(); } } diff --git a/src/main.rs b/src/main.rs index 6d4add3..17bb486 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,5 +16,5 @@ async fn main() { } async fn handler(req: Request) -> Result>, Infallible> { - Responder::text(format!("Hello World! {}", req.uri())) + Responder::text(&format!("Hello World! {}", req.uri())) } diff --git a/src/responder.rs b/src/responder.rs index cb59202..50cf549 100644 --- a/src/responder.rs +++ b/src/responder.rs @@ -8,18 +8,18 @@ pub struct Responder; impl Responder { pub fn not_found() -> Result>, Infallible> { - Self::response_using_builder(Self::create_builder(401), "Not Found".to_string()) + Self::response_using_builder(Self::create_builder(404), "Not Found") } pub fn unathorized() -> Result>, Infallible> { - Self::response_using_builder(Self::create_builder(401), "Unathorized".to_string()) + Self::response_using_builder(Self::create_builder(401), "Unathorized") } - pub fn text(response: String) -> Result>, Infallible> { + pub fn text(response: &str) -> Result>, Infallible> { Self::response_using_builder(Self::create_builder(200), response) } - pub fn json(json: T) -> Result>, Infallible> + pub fn json(json: &T) -> Result>, Infallible> where T: Serialize, { @@ -28,25 +28,27 @@ impl Responder { pub fn text_using_status( status: u16, - response: String, + response: &str, ) -> Result>, Infallible> { Self::response_using_builder(Self::create_builder(status), response) } - pub fn json_using_status(status: u16, json: T) -> Result>, Infallible> + pub fn json_using_status(status: u16, json: &T) -> Result>, Infallible> where T: Serialize, { let builder = Self::create_builder(status).header(CONTENT_TYPE, "application/json"); - Self::response_using_builder(builder, serde_json::to_string(&json).unwrap()) + Self::response_using_builder(builder, &serde_json::to_string(json).unwrap()) } fn response_using_builder( builder: Builder, - response: String, + response: &str, ) -> Result>, Infallible> { - Ok(builder.body(Full::new(Bytes::from(response))).unwrap()) + Ok(builder + .body(Full::::from(response.to_string())) + .unwrap()) } fn create_builder(status: u16) -> Builder {