mirror of https://github.com/rwf2/Rocket.git
Only override request methods via '_method' on POST.
This commit is contained in:
parent
a1878ad080
commit
d19cb0349c
|
@ -141,7 +141,7 @@ impl Rocket {
|
|||
// field which we use to reinterpret the request's method.
|
||||
let data_len = data.peek().len();
|
||||
let (min_len, max_len) = ("_method=get".len(), "_method=delete".len());
|
||||
if req.content_type().is_form() && data_len >= min_len {
|
||||
if req.method() == Method::Post && req.content_type().is_form() && data_len >= min_len {
|
||||
let form = unsafe {
|
||||
from_utf8_unchecked(&data.peek()[..min(data_len, max_len)])
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
extern crate rocket;
|
||||
|
||||
use rocket::request::Form;
|
||||
use rocket::http::Status;
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct FormData {
|
||||
|
@ -24,7 +25,7 @@ use rocket::http::ContentType;
|
|||
fn method_eval() {
|
||||
let rocket = rocket::ignite().mount("/", routes![bug]);
|
||||
|
||||
let mut req = MockRequest::new(Patch, "/")
|
||||
let mut req = MockRequest::new(Post, "/")
|
||||
.header(ContentType::Form)
|
||||
.body("_method=patch&form_data=Form+data");
|
||||
|
||||
|
@ -32,3 +33,15 @@ fn method_eval() {
|
|||
let body_str = response.body().and_then(|b| b.into_string());
|
||||
assert_eq!(body_str, Some("OK".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_passes_through() {
|
||||
let rocket = rocket::ignite().mount("/", routes![bug]);
|
||||
|
||||
let mut req = MockRequest::new(Get, "/")
|
||||
.header(ContentType::Form)
|
||||
.body("_method=patch&form_data=Form+data");
|
||||
|
||||
let mut response = req.dispatch_with(&rocket);
|
||||
assert_eq!(response.status(), Status::NotFound);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue