mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-05 01:02:42 +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.
32 lines
819 B
Rust
32 lines
819 B
Rust
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::response::Redirect;
|
|
|
|
#[get("/http")]
|
|
fn http() -> Redirect {
|
|
Redirect::to(uri!("http://rocket.rs"))
|
|
}
|
|
|
|
#[get("/rocket")]
|
|
fn redirect() -> Redirect {
|
|
Redirect::to("https://rocket.rs:80")
|
|
}
|
|
|
|
mod test_absolute_uris_okay {
|
|
use super::*;
|
|
use rocket::local::blocking::Client;
|
|
|
|
#[test]
|
|
fn redirect_works() {
|
|
let client = Client::debug_with(routes![http, redirect]).unwrap();
|
|
|
|
let response = client.get(uri!(http)).dispatch();
|
|
let location = response.headers().get_one("Location");
|
|
assert_eq!(location, Some("http://rocket.rs"));
|
|
|
|
let response = client.get(uri!(redirect)).dispatch();
|
|
let location = response.headers().get_one("Location");
|
|
assert_eq!(location, Some("https://rocket.rs:80"));
|
|
}
|
|
}
|