mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-08 02:32:37 +00:00
fa3e0334c1
This commit entirely rewrites Rocket's URI parsing routines and overhauls the 'uri!' macro resolving all known issues and removing any potential limitations for compile-time URI creation. This commit: * Introduces a new 'Reference' URI variant for URI-references. * Modifies 'Redirect' to accept 'TryFrom<Reference>'. * Introduces a new 'Asterisk' URI variant for parity. * Allows creation of any URI type from a string literal via 'uri!'. * Enables dynamic/static prefixing/suffixing of route URIs in 'uri!'. * Unifies 'Segments' and 'QuerySegments' into one generic 'Segments'. * Consolidates URI formatting types/traits into a 'uri::fmt' module. * Makes APIs more symmetric across URI types. It also includes the following less-relevant changes: * Implements 'FromParam' for a single-segment 'PathBuf'. * Adds 'FileName::is_safe()'. * No longer reparses upstream request URIs. Resolves #842. Resolves #853. Resolves #998.
37 lines
985 B
Rust
37 lines
985 B
Rust
use rocket::{Rocket, Build};
|
|
use rocket::local::blocking::Client;
|
|
|
|
mod inner {
|
|
use rocket::uri;
|
|
|
|
#[rocket::get("/")]
|
|
pub fn hello() -> String {
|
|
format!("Hello! Try {}.", uri!(super::hello_name("Rust 2018")))
|
|
}
|
|
}
|
|
|
|
#[rocket::get("/<name>")]
|
|
fn hello_name(name: String) -> String {
|
|
format!("Hello, {}! This is {}.", name, rocket::uri!(hello_name(&name)))
|
|
}
|
|
|
|
fn rocket() -> Rocket<Build> {
|
|
rocket::build()
|
|
.mount("/", rocket::routes![hello_name])
|
|
.mount("/", rocket::routes![inner::hello])
|
|
}
|
|
|
|
#[test]
|
|
fn test_inner_hello() {
|
|
let client = Client::debug(rocket()).unwrap();
|
|
let response = client.get("/").dispatch();
|
|
assert_eq!(response.into_string(), Some("Hello! Try /Rust%202018.".into()));
|
|
}
|
|
|
|
#[test]
|
|
fn test_hello_name() {
|
|
let client = Client::debug(rocket()).unwrap();
|
|
let response = client.get("/Rust%202018").dispatch();
|
|
assert_eq!(response.into_string().unwrap(), "Hello, Rust 2018! This is /Rust%202018.");
|
|
}
|