diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2023-02-01 20:34:22 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2023-02-01 20:34:22 -0500 |
commit | 2026a8f4579b1db0f6e5e7b11ac33c13969adb6c (patch) | |
tree | daa13419b7227462775e325a4f5f60f2ed33c1da /src/types/http.rs | |
parent | remove b64 imgs (diff) | |
download | xssbook-2026a8f4579b1db0f6e5e7b11ac33c13969adb6c.tar.gz xssbook-2026a8f4579b1db0f6e5e7b11ac33c13969adb6c.tar.bz2 xssbook-2026a8f4579b1db0f6e5e7b11ac33c13969adb6c.zip |
static serve refactor
Diffstat (limited to 'src/types/http.rs')
-rw-r--r-- | src/types/http.rs | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/src/types/http.rs b/src/types/http.rs index 8524b15..06674ca 100644 --- a/src/types/http.rs +++ b/src/types/http.rs @@ -1,11 +1,8 @@ use axum::{ - body::Body, headers::HeaderName, - http::{HeaderValue, Request, StatusCode}, + http::{HeaderValue, StatusCode}, response::{IntoResponse, Response}, }; -use tower::ServiceExt; -use tower_http::services::ServeFile; use tracing::instrument; #[derive(Debug)] @@ -58,24 +55,6 @@ impl ResponseCode { ); res } - - #[instrument()] - pub async fn file(self, path: &str) -> Response { - if !path.chars().any(|c| c == '.') { - return Self::BadRequest.text("Folders cannot be served"); - } - let path = format!("public{path}"); - let svc = ServeFile::new(path); - let Ok(mut res) = svc.oneshot(Request::new(Body::empty())).await else { - tracing::error!("Error while fetching file"); - return Self::InternalServerError.text("Error while fetching file"); - }; - if res.status() != StatusCode::OK { - return Self::NotFound.text("File not found"); - } - *res.status_mut() = self.code(); - res.into_response() - } } pub type Result<T> = std::result::Result<T, Response>; |