2019-08-20 23:53:00 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2016-12-26 03:32:32 +00:00
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2016-12-26 03:32:32 +00:00
|
|
|
|
|
|
|
use rocket::request::Form;
|
|
|
|
|
|
|
|
#[derive(FromForm)]
|
|
|
|
struct FormData {
|
|
|
|
form_data: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[patch("/", data = "<form_data>")]
|
|
|
|
fn bug(form_data: Form<FormData>) -> &'static str {
|
2018-09-26 08:13:57 +00:00
|
|
|
assert_eq!("Form data", form_data.form_data);
|
2016-12-26 03:32:32 +00:00
|
|
|
"OK"
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:51:00 +00:00
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2017-01-05 20:51:00 +00:00
|
|
|
use rocket::http::{Status, ContentType};
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
#[rocket::async_test]
|
|
|
|
async fn method_eval() {
|
2020-06-14 15:57:53 +00:00
|
|
|
let client = Client::new(rocket::ignite().mount("/", routes![bug])).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
let mut response = client.post("/")
|
2017-01-05 20:51:00 +00:00
|
|
|
.header(ContentType::Form)
|
2017-06-06 20:41:04 +00:00
|
|
|
.body("_method=patch&form_data=Form+data")
|
2019-08-24 17:27:10 +00:00
|
|
|
.dispatch().await;
|
2017-01-05 20:51:00 +00:00
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
assert_eq!(response.body_string().await, Some("OK".into()));
|
2017-01-05 20:51:00 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
#[rocket::async_test]
|
|
|
|
async fn get_passes_through() {
|
2020-06-14 15:57:53 +00:00
|
|
|
let client = Client::new(rocket::ignite().mount("/", routes![bug])).await.unwrap();
|
2017-06-06 20:41:04 +00:00
|
|
|
let response = client.get("/")
|
2017-01-05 20:51:00 +00:00
|
|
|
.header(ContentType::Form)
|
2017-06-06 20:41:04 +00:00
|
|
|
.body("_method=patch&form_data=Form+data")
|
2019-08-24 17:27:10 +00:00
|
|
|
.dispatch().await;
|
2017-01-05 20:51:00 +00:00
|
|
|
|
|
|
|
assert_eq!(response.status(), Status::NotFound);
|
|
|
|
}
|
2016-12-31 04:33:51 +00:00
|
|
|
}
|