mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-31 23:02:37 +00:00
5d9035ddc1
In brief, this commit: * Updates to the latest upstream 'cookie', fixing a memory leak. * Make changes to 'CookieJar' observable only through 'pending()'. * Deprecates 'Client::new()' in favor of 'Client::tracked()'. * Makes 'dispatch()' on tracked 'Client's synchronize on cookies. * Makes 'Client::untracked()' actually untracked. This commit updates to the latest 'cookie' which removes support for 'Sync' cookie jars. Instead of relying on 'cookie', this commit implements an op-log based 'CookieJar' which internally keeps track of changes. The API is such that changes are only observable through specialized '_pending()' methods.
58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::response::Redirect;
|
|
use rocket::http::uri::Uri;
|
|
|
|
const NAME: &str = "John[]|\\%@^";
|
|
|
|
#[get("/hello/<name>")]
|
|
fn hello(name: String) -> String {
|
|
format!("Hello, {}!", name)
|
|
}
|
|
|
|
#[get("/raw")]
|
|
fn raw_redirect() -> Redirect {
|
|
Redirect::to(format!("/hello/{}", Uri::percent_encode(NAME)))
|
|
}
|
|
|
|
#[get("/uri")]
|
|
fn uri_redirect() -> Redirect {
|
|
Redirect::to(uri!(hello: NAME))
|
|
}
|
|
|
|
fn rocket() -> rocket::Rocket {
|
|
rocket::ignite().mount("/", routes![hello, uri_redirect, raw_redirect])
|
|
}
|
|
|
|
|
|
mod tests {
|
|
use super::*;
|
|
use rocket::local::blocking::Client;
|
|
use rocket::http::{Status, uri::Uri};
|
|
|
|
#[test]
|
|
fn uri_percent_encoding_redirect() {
|
|
let expected_location = vec!["/hello/John%5B%5D%7C%5C%25@%5E"];
|
|
let client = Client::tracked(rocket()).unwrap();
|
|
|
|
let response = client.get("/raw").dispatch();
|
|
let location: Vec<_> = response.headers().get("location").collect();
|
|
assert_eq!(response.status(), Status::SeeOther);
|
|
assert_eq!(&location, &expected_location);
|
|
|
|
let response = client.get("/uri").dispatch();
|
|
let location: Vec<_> = response.headers().get("location").collect();
|
|
assert_eq!(response.status(), Status::SeeOther);
|
|
assert_eq!(&location, &expected_location);
|
|
}
|
|
|
|
#[test]
|
|
fn uri_percent_encoding_get() {
|
|
let client = Client::tracked(rocket()).unwrap();
|
|
let name = Uri::percent_encode(NAME);
|
|
let response = client.get(format!("/hello/{}", name)).dispatch();
|
|
assert_eq!(response.status(), Status::Ok);
|
|
assert_eq!(response.into_string().unwrap(), format!("Hello, {}!", NAME));
|
|
}
|
|
}
|