summaryrefslogtreecommitdiff
path: root/src/types/http.rs
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-02-01 20:34:22 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-02-01 20:34:22 -0500
commit2026a8f4579b1db0f6e5e7b11ac33c13969adb6c (patch)
treedaa13419b7227462775e325a4f5f60f2ed33c1da /src/types/http.rs
parentremove b64 imgs (diff)
downloadxssbook-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.rs23
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>;