Allow head decorator and options via route decorator.

This commit is contained in:
Sergio Benitez 2016-12-30 00:50:30 -06:00
parent bad0c20cda
commit 2de006d9f9
5 changed files with 40 additions and 6 deletions

View File

@ -290,5 +290,8 @@ method_decorator!(get_decorator, Get);
method_decorator!(put_decorator, Put); method_decorator!(put_decorator, Put);
method_decorator!(post_decorator, Post); method_decorator!(post_decorator, Post);
method_decorator!(delete_decorator, Delete); method_decorator!(delete_decorator, Delete);
method_decorator!(patch_decorator, Patch);
method_decorator!(head_decorator, Head); method_decorator!(head_decorator, Head);
method_decorator!(patch_decorator, Patch);
// TODO: Allow this once Diesel incompatibility is fixed.
// method_decorator!(options_decorator, Options);

View File

@ -160,5 +160,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
"delete" => delete_decorator, "delete" => delete_decorator,
"head" => head_decorator, "head" => head_decorator,
"patch" => patch_decorator "patch" => patch_decorator
// TODO: Allow this once Diesel incompatibility is fixed. Fix docs too.
// "options" => options_decorator
); );
} }

View File

@ -134,8 +134,8 @@ impl RouteParams {
fn is_valid_method(method: Method) -> bool { fn is_valid_method(method: Method) -> bool {
use rocket::http::Method::*; use rocket::http::Method::*;
match method { match method {
Get | Put | Post | Delete | Patch => true, Get | Put | Post | Delete | Head | Patch | Options => true,
_ => false Trace | Connect => false
} }
} }

View File

@ -6,6 +6,7 @@ extern crate rocket;
#[get("")] #[get("")]
fn get() -> &'static str { "hi" } fn get() -> &'static str { "hi" }
fn main() { #[get("/")]
let _ = routes![get]; fn get_empty() { }
}
fn main() { }

View File

@ -0,0 +1,28 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
#[get("/")]
fn get() { }
#[put("/")]
fn put() { }
#[post("/")]
fn post() { }
#[delete("/")]
fn delete() { }
#[head("/")]
fn head() { }
#[patch("/")]
fn patch() { }
// TODO: Allow this once Diesel incompatibility is fixed.
// #[options("/")]
// fn options() { }
fn main() { }