From c0d28918d45f0b523cea50ebc51abb794c334334 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Tue, 2 Jun 2020 00:04:24 +0200 Subject: [PATCH] refactor: prefer const for default content type --- src/error_page.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/error_page.rs b/src/error_page.rs index 82f8608..4c05c6e 100644 --- a/src/error_page.rs +++ b/src/error_page.rs @@ -1,4 +1,3 @@ -use iron::mime; use iron::prelude::*; use iron::status; use iron::AfterMiddleware; @@ -8,6 +7,7 @@ use std::path::Path; const PAGE_404: &str = "

404

Content could not found

"; const PAGE_50X: &str = "

50x

SERVICE is temporarily unavailable due an unexpected error

"; +const CONTENT_TYPE: &str = "text/html"; /// Custom Error pages middleware for Iron pub struct ErrorPage { @@ -38,28 +38,27 @@ impl ErrorPage { impl AfterMiddleware for ErrorPage { fn after(&self, req: &mut Request, resp: Response) -> IronResult { - let content_type = "text/html".parse::().unwrap(); let mut no_status_error = false; let mut resp = match resp.status { Some(status::NotFound) => { - Response::with((content_type, status::NotFound, self.page404.as_str())) + Response::with((CONTENT_TYPE, status::NotFound, self.page404.as_str())) } Some(status::InternalServerError) => Response::with(( - content_type, + CONTENT_TYPE, status::InternalServerError, self.page50x.as_str(), )), Some(status::BadGateway) => { - Response::with((content_type, status::BadGateway, self.page50x.as_str())) + Response::with((CONTENT_TYPE, status::BadGateway, self.page50x.as_str())) } Some(status::ServiceUnavailable) => Response::with(( - content_type, + CONTENT_TYPE, status::ServiceUnavailable, self.page50x.as_str(), )), Some(status::GatewayTimeout) => { - Response::with((content_type, status::GatewayTimeout, self.page50x.as_str())) + Response::with((CONTENT_TYPE, status::GatewayTimeout, self.page50x.as_str())) } _ => { no_status_error = true; @@ -69,7 +68,7 @@ impl AfterMiddleware for ErrorPage { // Empty response body only on HEAD requests and status error (404,50x) if req.method == iron::method::Head && !no_status_error { - resp.set_mut(Vec::new()); + resp.set_mut(vec![]); } Ok(resp) -- libgit2 1.7.2