From 244d0e9ed536f9a80b355789257d99ce3c5d7a72 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Tue, 9 Apr 2019 00:39:11 -0700 Subject: [PATCH] Fixed unaccurate redirect to index.html --- src/swagger.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/swagger.rs b/src/swagger.rs index 0b86d6c..32e7850 100644 --- a/src/swagger.rs +++ b/src/swagger.rs @@ -16,7 +16,12 @@ pub fn get_routes() -> Vec { #[get("/", rank = 9)] fn index(origin: &Origin) -> Redirect { - let redirect = Redirect::permanent(origin.path().to_owned() + "index.html"); + let mut new_path = origin.path().to_owned(); + if !new_path.ends_with("/") { + new_path.push_str("/"); + } + new_path.push_str("index.html"); + let redirect = Redirect::permanent(new_path); return redirect; } @@ -35,6 +40,7 @@ fn test_index_redirect() { let client = &env.client; let response = client.get("/swagger").dispatch(); assert_eq!(response.status(), Status::PermanentRedirect); + assert_eq!(response.headers().get_one("Location"), Some("/swagger/index.html")); } #[test]