aboutsummaryrefslogtreecommitdiffstats
path: root/src/listing.rs
diff options
context:
space:
mode:
authorwyhaya <wyhaya@gmail.com>2019-07-08 03:05:48 +0000
committerwyhaya <wyhaya@gmail.com>2019-07-08 03:05:48 +0000
commit063b8dbc5192a46a0f9e30c5efcd1047aca8bbbb (patch)
treeff0a2daf29fe07bc5217d2da180e87af612815ce /src/listing.rs
parentadd space (diff)
downloadminiserve-063b8dbc5192a46a0f9e30c5efcd1047aca8bbbb.tar.gz
miniserve-063b8dbc5192a46a0f9e30c5efcd1047aca8bbbb.zip
fix parent directory
Diffstat (limited to 'src/listing.rs')
-rw-r--r--src/listing.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/listing.rs b/src/listing.rs
index ee9c581..4a69108 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -138,7 +138,6 @@ pub fn directory_listing<S>(
let base = Path::new(serve_path);
let random_route = format!("/{}", random_route.unwrap_or_default());
let is_root = base.parent().is_none() || req.path() == random_route;
- let page_parent = base.parent().map(|p| p.display().to_string());
let current_dir = match base.strip_prefix(random_route) {
Ok(c_d) => Path::new("/").join(c_d),
Err(_) => base.to_path_buf(),
@@ -285,6 +284,19 @@ pub fn directory_listing<S>(
.chunked()
.body(Body::Streaming(Box::new(rx))))
} else {
+ // Redirect to directory
+ if !renderer::has_trailing(&serve_path) {
+ let query = match req.query_string() {
+ "" => String::new(),
+ _ => format!("?{}", req.query_string())
+ };
+ return Ok(
+ HttpResponse::MovedPermanenty()
+ .header("Location", format!("{}/{}", serve_path, query))
+ .body("301")
+ );
+ }
+
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(
@@ -292,7 +304,6 @@ pub fn directory_listing<S>(
serve_path,
entries,
is_root,
- page_parent,
query_params.sort,
query_params.order,
default_color_scheme,