mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
Fix duplicate tail of StaticFiles with index_file
Map from 0.6 to master
This commit is contained in:
parent
800c404c72
commit
a9425a866b
17
src/fs.rs
17
src/fs.rs
@ -676,10 +676,6 @@ impl<S: 'static> Handler<S> for StaticFiles<S> {
|
|||||||
// TODO: It'd be nice if there were a good usable URL manipulation
|
// TODO: It'd be nice if there were a good usable URL manipulation
|
||||||
// library
|
// library
|
||||||
let mut new_path: String = req.path().to_owned();
|
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('/') {
|
if !new_path.ends_with('/') {
|
||||||
new_path.push('/');
|
new_path.push('/');
|
||||||
}
|
}
|
||||||
@ -1205,8 +1201,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_redirect_to_index() {
|
fn test_redirect_to_index() {
|
||||||
let st = StaticFiles::new(".").index_file("index.html");
|
let st = StaticFiles::new(".").index_file("index.html");
|
||||||
let mut req = HttpRequest::default();
|
let req = TestRequest::default().uri("/tests").finish();
|
||||||
req.match_info_mut().add_static("tail", "tests");
|
|
||||||
|
|
||||||
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
||||||
let resp = resp.as_msg();
|
let resp = resp.as_msg();
|
||||||
@ -1216,8 +1211,7 @@ mod tests {
|
|||||||
"/tests/index.html"
|
"/tests/index.html"
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut req = HttpRequest::default();
|
let req = TestRequest::default().uri("/tests/").finish();
|
||||||
req.match_info_mut().add_static("tail", "tests/");
|
|
||||||
|
|
||||||
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
||||||
let resp = resp.as_msg();
|
let resp = resp.as_msg();
|
||||||
@ -1230,16 +1224,15 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_redirect_to_index_nested() {
|
fn test_redirect_to_index_nested() {
|
||||||
let st = StaticFiles::new(".").index_file("mod.rs");
|
let st = StaticFiles::new(".").index_file("Cargo.toml");
|
||||||
let mut req = HttpRequest::default();
|
let req = TestRequest::default().uri("/tools/wsload").finish();
|
||||||
req.match_info_mut().add_static("tail", "src/client");
|
|
||||||
|
|
||||||
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
let resp = st.handle(req).respond_to(&HttpRequest::default()).unwrap();
|
||||||
let resp = resp.as_msg();
|
let resp = resp.as_msg();
|
||||||
assert_eq!(resp.status(), StatusCode::FOUND);
|
assert_eq!(resp.status(), StatusCode::FOUND);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::LOCATION).unwrap(),
|
resp.headers().get(header::LOCATION).unwrap(),
|
||||||
"/src/client/mod.rs"
|
"/tools/wsload/Cargo.toml"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user