2019-08-20 23:53:00 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2017-05-27 02:48:50 +00:00
|
|
|
|
2018-06-28 15:55:15 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2017-05-27 02:48:50 +00:00
|
|
|
|
2018-10-23 08:23:11 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2018-10-23 20:22:26 +00:00
|
|
|
use rocket::http::ext::Normalize;
|
2017-05-27 02:48:50 +00:00
|
|
|
use rocket::Route;
|
|
|
|
|
|
|
|
#[get("/<path..>")]
|
|
|
|
fn files(route: &Route, path: PathBuf) -> String {
|
2018-10-23 20:22:26 +00:00
|
|
|
Path::new(route.base()).join(path).normalized_str().to_string()
|
2017-05-27 02:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mod route_guard_tests {
|
|
|
|
use super::*;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-05-27 02:48:50 +00:00
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
async fn assert_path(client: &Client, path: &str) {
|
|
|
|
let mut res = client.get(path).dispatch().await;
|
|
|
|
assert_eq!(res.body_string().await, Some(path.into()));
|
2017-05-27 02:48:50 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
#[rocket::async_test]
|
|
|
|
async fn check_mount_path() {
|
2017-05-27 02:48:50 +00:00
|
|
|
let rocket = rocket::ignite()
|
|
|
|
.mount("/first", routes![files])
|
|
|
|
.mount("/second", routes![files]);
|
|
|
|
|
2020-06-14 15:57:53 +00:00
|
|
|
let client = Client::new(rocket).await.unwrap();
|
2019-08-24 17:27:10 +00:00
|
|
|
assert_path(&client, "/first/some/path").await;
|
|
|
|
assert_path(&client, "/second/some/path").await;
|
|
|
|
assert_path(&client, "/first/second/b/c").await;
|
|
|
|
assert_path(&client, "/second/a/b/c").await;
|
2017-05-27 02:48:50 +00:00
|
|
|
}
|
|
|
|
}
|