diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-28 18:04:00 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2023-01-28 18:04:00 -0500 |
commit | b58654fd70958d89b344a6f7acac204f67ae9879 (patch) | |
tree | 60a1960d0d265c9f661e633022164f33e099c81c /src/types/http.rs | |
parent | new rust, clippy (diff) | |
download | xssbook-b58654fd70958d89b344a6f7acac204f67ae9879.tar.gz xssbook-b58654fd70958d89b344a6f7acac204f67ae9879.tar.bz2 xssbook-b58654fd70958d89b344a6f7acac204f67ae9879.zip |
fmt
Diffstat (limited to 'src/types/http.rs')
-rw-r--r-- | src/types/http.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/types/http.rs b/src/types/http.rs index 0e7b703..8524b15 100644 --- a/src/types/http.rs +++ b/src/types/http.rs @@ -1,4 +1,9 @@ -use axum::{response::{IntoResponse, Response}, http::{StatusCode, Request, HeaderValue}, body::Body, headers::HeaderName}; +use axum::{ + body::Body, + headers::HeaderName, + http::{HeaderValue, Request, StatusCode}, + response::{IntoResponse, Response}, +}; use tower::ServiceExt; use tower_http::services::ServeFile; use tracing::instrument; @@ -12,11 +17,10 @@ pub enum ResponseCode { Forbidden, NotFound, ImATeapot, - InternalServerError + InternalServerError, } impl ResponseCode { - const fn code(self) -> StatusCode { match self { Self::Success => StatusCode::OK, @@ -26,7 +30,7 @@ impl ResponseCode { Self::Forbidden => StatusCode::FORBIDDEN, Self::NotFound => StatusCode::NOT_FOUND, Self::ImATeapot => StatusCode::IM_A_TEAPOT, - Self::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR + Self::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, } } @@ -39,7 +43,8 @@ impl ResponseCode { pub fn json(self, json: &str) -> Response { let mut res = (self.code(), json.to_owned()).into_response(); res.headers_mut().insert( - HeaderName::from_static("content-type"), HeaderValue::from_static("application/json"), + HeaderName::from_static("content-type"), + HeaderValue::from_static("application/json"), ); res } @@ -48,14 +53,15 @@ impl ResponseCode { pub fn html(self, json: &str) -> Response { let mut res = (self.code(), json.to_owned()).into_response(); res.headers_mut().insert( - HeaderName::from_static("content-type"), HeaderValue::from_static("text/html"), + HeaderName::from_static("content-type"), + HeaderValue::from_static("text/html"), ); res } #[instrument()] pub async fn file(self, path: &str) -> Response { - if !path.chars().any(|c| c == '.' ) { + if !path.chars().any(|c| c == '.') { return Self::BadRequest.text("Folders cannot be served"); } let path = format!("public{path}"); @@ -72,4 +78,4 @@ impl ResponseCode { } } -pub type Result<T> = std::result::Result<T, Response>;
\ No newline at end of file +pub type Result<T> = std::result::Result<T, Response>; |