mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-05 17:22:36 +00:00
1fb061496d
This commit completely overhauls Rocket's configuration systems, basing it on the new Figment library. It includes many breaking changes pertaining to configuration. They are: * "Environments" are replaced by "profiles". * 'ROCKET_PROFILE' takes the place of 'ROCKET_ENV'. * Profile names are now arbitrary, but 'debug' and 'release' are given special treatment as default profiles for the debug and release compilation profiles. * A 'default' profile now sits along-side the meta 'global' profile. * The concept of "extras" is no longer present; users can extract any values they want from the configured 'Figment'. * The 'Poolable' trait takes an '&Config'. * The 'secrets' feature is disabled by default. * It is a hard error if 'secrets' is enabled under the 'release' profile and no 'secret_key' is configured. * 'ConfigBuilder' no longer exists: all fields of 'Config' are public with public constructors for each type. * 'keep_alive' is disabled with '0', not 'false' or 'off'. * Inlined error variants into the 'Error' structure. * 'LoggingLevel' is now 'LogLevel'. * Limits can now be specified in SI units: "1 MiB". The summary of other changes are: * The default config file can be configured with 'ROCKET_CONFIG'. * HTTP/1 and HTTP/2 keep-alive configuration is restored. * 'ctrlc' is now a recognized config option. * 'serde' is now a core dependency. * TLS misconfiguration errors are improved. * Several example use '_' as the return type of '#[launch]' fns. * 'AdHoc::config()' was added for simple config extraction. * Added more documentation for using 'Limits'. * Launch information is no longer treated specially. * The configuration guide was rewritten. Resolves #852. Resolves #209. Closes #1404. Closes #652.
71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::request::Form;
|
|
|
|
#[derive(FromForm)]
|
|
struct Simple {
|
|
value: String
|
|
}
|
|
|
|
#[post("/", data = "<form>")]
|
|
fn index(form: Form<Simple>) -> String {
|
|
form.into_inner().value
|
|
}
|
|
|
|
mod limits_tests {
|
|
use rocket;
|
|
use rocket::local::blocking::Client;
|
|
use rocket::http::{Status, ContentType};
|
|
use rocket::data::Limits;
|
|
|
|
fn rocket_with_forms_limit(limit: u64) -> rocket::Rocket {
|
|
let limits = Limits::default().limit("forms", limit.into());
|
|
let config = rocket::Config::figment().merge(("limits", limits));
|
|
rocket::custom(config).mount("/", routes![super::index])
|
|
}
|
|
|
|
#[test]
|
|
fn large_enough() {
|
|
let client = Client::tracked(rocket_with_forms_limit(128)).unwrap();
|
|
let response = client.post("/")
|
|
.body("value=Hello+world")
|
|
.header(ContentType::Form)
|
|
.dispatch();
|
|
|
|
assert_eq!(response.into_string(), Some("Hello world".into()));
|
|
}
|
|
|
|
#[test]
|
|
fn just_large_enough() {
|
|
let client = Client::tracked(rocket_with_forms_limit(17)).unwrap();
|
|
let response = client.post("/")
|
|
.body("value=Hello+world")
|
|
.header(ContentType::Form)
|
|
.dispatch();
|
|
|
|
assert_eq!(response.into_string(), Some("Hello world".into()));
|
|
}
|
|
|
|
#[test]
|
|
fn much_too_small() {
|
|
let client = Client::tracked(rocket_with_forms_limit(4)).unwrap();
|
|
let response = client.post("/")
|
|
.body("value=Hello+world")
|
|
.header(ContentType::Form)
|
|
.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::UnprocessableEntity);
|
|
}
|
|
|
|
#[test]
|
|
fn contracted() {
|
|
let client = Client::tracked(rocket_with_forms_limit(10)).unwrap();
|
|
let response = client.post("/")
|
|
.body("value=Hello+world")
|
|
.header(ContentType::Form)
|
|
.dispatch();
|
|
|
|
assert_eq!(response.into_string(), Some("Hell".into()));
|
|
}
|
|
}
|