mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-09 03:02:45 +00:00
3a44b1b28e
Prior to this commit, several `RouteUri` fields were public, allowing those values to be changed at will. These changes were at times not reflected by the rest of the library, meaning that the values in the route URI structure for a route became incoherent with the reflected values. This commit makes all fields private, forcing all changes to go through methods that can ensure coherence. All values remain accessible via getter methods.
34 lines
944 B
Rust
34 lines
944 B
Rust
#[macro_use] extern crate rocket;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use rocket::http::ext::Normalize;
|
|
use rocket::Route;
|
|
|
|
#[get("/<path..>")]
|
|
fn files(route: &Route, path: PathBuf) -> String {
|
|
Path::new(&route.uri.base()).join(path).normalized_str().to_string()
|
|
}
|
|
|
|
mod route_guard_tests {
|
|
use super::*;
|
|
use rocket::local::blocking::Client;
|
|
|
|
fn assert_path(client: &Client, path: &str) {
|
|
let res = client.get(path).dispatch();
|
|
assert_eq!(res.into_string(), Some(path.into()));
|
|
}
|
|
|
|
#[test]
|
|
fn check_mount_path() {
|
|
let rocket = rocket::build()
|
|
.mount("/first", routes![files])
|
|
.mount("/second", routes![files]);
|
|
|
|
let client = Client::debug(rocket).unwrap();
|
|
assert_path(&client, "/first/some/path");
|
|
assert_path(&client, "/second/some/path");
|
|
assert_path(&client, "/first/second/b/c");
|
|
assert_path(&client, "/second/a/b/c");
|
|
}
|
|
}
|