From 2026a8f4579b1db0f6e5e7b11ac33c13969adb6c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 1 Feb 2023 20:34:22 -0500 Subject: static serve refactor --- src/types/http.rs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'src/types/http.rs') 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 = std::result::Result; -- cgit v1.2.3-freya