aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVojtěch Pejša <vojtechpejsa7@gmail.com>2019-03-25 13:44:45 +0000
committerVojtěch Pejša <vojtechpejsa7@gmail.com>2019-04-04 08:51:00 +0000
commit1e8783e23c3c5e64acc40464329b64e3de6e2a20 (patch)
tree8db4e59e27707902099bc72c8f9227ef31deaa97 /src
parentRefactoring (diff)
downloadminiserve-1e8783e23c3c5e64acc40464329b64e3de6e2a20.tar.gz
miniserve-1e8783e23c3c5e64acc40464329b64e3de6e2a20.zip
Document file upload.
Diffstat (limited to '')
-rw-r--r--src/file_upload.rs11
-rw-r--r--src/main.rs2
2 files changed, 10 insertions, 3 deletions
diff --git a/src/file_upload.rs b/src/file_upload.rs
index f72ab8b..c0ec95f 100644
--- a/src/file_upload.rs
+++ b/src/file_upload.rs
@@ -9,7 +9,8 @@ use std::{
path::{Component, PathBuf},
};
-pub fn save_file(
+/// Create future to save file.
+fn save_file(
field: multipart::Field<dev::Payload>,
file_path: PathBuf,
) -> Box<Future<Item = i64, Error = Error>> {
@@ -30,7 +31,8 @@ pub fn save_file(
)
}
-pub fn handle_multipart(
+/// Create new future to handle file as multipart data.
+fn handle_multipart(
item: multipart::MultipartItem<dev::Payload>,
mut file_path: PathBuf,
) -> Box<Stream<Item = i64, Error = Error>> {
@@ -65,6 +67,11 @@ pub fn handle_multipart(
}
}
+/// Handle incoming request to upload file.
+/// Target file path is expected as path parameter in URI and is interpreted as relative from
+/// server root directory. Any path which will go outside of this directory is considered
+/// invalid.
+/// This method returns future.
pub fn upload_file(req: &HttpRequest<crate::MiniserveConfig>) -> FutureResponse<HttpResponse> {
if !req.query().contains_key("path") {
return Box::new(future::ok(
diff --git a/src/main.rs b/src/main.rs
index 37a3226..fb7e321 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -197,7 +197,7 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> {
let random_route = app.state().random_route.clone().unwrap_or_default();
let full_route = format!("/{}", random_route);
- //allow file upload
+ // Allow file upload
let app = app.resource("/upload", |r| {
r.method(Method::POST).f(file_upload::upload_file)
});