diff options
author | Vojtěch Pejša <vojtechpejsa7@gmail.com> | 2019-04-09 18:57:57 +0000 |
---|---|---|
committer | Vojtěch Pejša <vojtechpejsa7@gmail.com> | 2019-04-09 18:57:57 +0000 |
commit | 786a0e3e079469b0d57d7d870ec6dbfd6b921f7c (patch) | |
tree | 158dcca16d98eb150a678b7ee4c730572b8dcca5 /src/file_upload.rs | |
parent | Refactor file upload. (diff) | |
download | miniserve-786a0e3e079469b0d57d7d870ec6dbfd6b921f7c.tar.gz miniserve-786a0e3e079469b0d57d7d870ec6dbfd6b921f7c.zip |
Change HTTP response code and cleanup previus commit.
Diffstat (limited to 'src/file_upload.rs')
-rw-r--r-- | src/file_upload.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/file_upload.rs b/src/file_upload.rs index 5ef793d..4a0ae1f 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -105,9 +105,10 @@ pub fn upload_file(req: &HttpRequest<crate::MiniserveConfig>) -> FutureResponse< .to_str() .unwrap_or("/") .to_owned(); - let app_root_dir = match req.state().path.canonicalize() { - Ok(path) => path, - Err(_) => return Box::new(create_error_response("Internal server error", &return_path)), + let app_root_dir = if let Ok(dir) = req.state().path.canonicalize() { + dir + } else { + return Box::new(create_error_response("Internal server error", &return_path)); }; let path = match Query::<QueryParameters>::extract(req) { Ok(query) => { @@ -151,13 +152,13 @@ pub fn upload_file(req: &HttpRequest<crate::MiniserveConfig>) -> FutureResponse< ) } -// Convenience method for creating response errors, when file upload fails. +/// Convenience method for creating response errors, if file upload fails. fn create_error_response( description: &str, return_path: &str, ) -> FutureResult<HttpResponse, actix_web::error::Error> { future::ok( - HttpResponse::NotAcceptable() + HttpResponse::BadRequest() .content_type("text/html; charset=utf-8") .body(file_upload_error(description, return_path).into_string()), ) |