mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-03 16:22: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.
57 lines
1.2 KiB
Rust
57 lines
1.2 KiB
Rust
use rocket;
|
|
|
|
use rocket::{get, routes};
|
|
use rocket::request::{Form, FromForm, FromFormValue};
|
|
use rocket::response::Responder;
|
|
|
|
#[derive(FromFormValue)]
|
|
enum Thing {
|
|
A,
|
|
B,
|
|
C,
|
|
}
|
|
|
|
impl std::fmt::Display for Thing {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match *self {
|
|
Thing::A => write!(f, "a"),
|
|
Thing::B => write!(f, "b"),
|
|
Thing::C => write!(f, "c"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(FromForm)]
|
|
struct ThingForm {
|
|
thing: Thing,
|
|
}
|
|
|
|
#[derive(Responder)]
|
|
struct DerivedResponder {
|
|
data: String,
|
|
}
|
|
|
|
#[get("/")]
|
|
fn index() -> DerivedResponder {
|
|
DerivedResponder { data: "hello".to_string() }
|
|
}
|
|
|
|
#[get("/?<params..>")]
|
|
fn number(params: Form<ThingForm>) -> DerivedResponder {
|
|
DerivedResponder { data: params.thing.to_string() }
|
|
}
|
|
|
|
#[test]
|
|
fn test_derive_reexports() {
|
|
use rocket::local::blocking::Client;
|
|
|
|
let rocket = rocket::ignite().mount("/", routes![index, number]);
|
|
let client = Client::tracked(rocket).unwrap();
|
|
|
|
let response = client.get("/").dispatch();
|
|
assert_eq!(response.into_string().unwrap(), "hello");
|
|
|
|
let response = client.get("/?thing=b").dispatch();
|
|
assert_eq!(response.into_string().unwrap(), "b");
|
|
}
|