1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-19 14:49:01 +00:00

Fix duplicate tail of StaticFiles with index_file. (#344)

This commit is contained in:
Gary Hai 2018-06-26 00:37:24 +08:00 committed by Douman
parent 1fcf1d4a49
commit c2979760b5

View file

@ -653,10 +653,6 @@ impl<S: 'static> Handler<S> for StaticFiles<S> {
// TODO: It'd be nice if there were a good usable URL manipulation
// library
let mut new_path: String = req.path().to_owned();
for el in relpath.iter() {
new_path.push_str(&el.to_string_lossy());
new_path.push('/');
}
if !new_path.ends_with('/') {
new_path.push('/');
}
@ -1017,7 +1013,8 @@ mod tests {
#[test]
fn test_redirect_to_index() {
let mut st = StaticFiles::new(".").index_file("index.html");
let mut req = HttpRequest::default();
let mut req = TestRequest::default().uri("/tests").finish();
req.match_info_mut().add("tail", "tests");
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
@ -1028,7 +1025,7 @@ mod tests {
"/tests/index.html"
);
let mut req = HttpRequest::default();
let mut req = TestRequest::default().uri("/tests/").finish();
req.match_info_mut().add("tail", "tests/");
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
@ -1043,7 +1040,7 @@ mod tests {
#[test]
fn test_redirect_to_index_nested() {
let mut st = StaticFiles::new(".").index_file("Cargo.toml");
let mut req = HttpRequest::default();
let mut req = TestRequest::default().uri("/tools/wsload").finish();
req.match_info_mut().add("tail", "tools/wsload");
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();