2016-09-04 20:51:16 +00:00
|
|
|
#![feature(plugin)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
2016-09-04 20:51:16 +00:00
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
use std::fmt;
|
2016-10-14 01:39:23 +00:00
|
|
|
use rocket::request::{Request, FromRequest, RequestOutcome};
|
2016-09-04 20:51:16 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct HeaderCount(usize);
|
|
|
|
|
|
|
|
impl fmt::Display for HeaderCount {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 06:20:49 +00:00
|
|
|
impl<'r> FromRequest<'r> for HeaderCount {
|
2016-09-04 20:51:16 +00:00
|
|
|
type Error = ();
|
2016-10-14 01:39:23 +00:00
|
|
|
fn from_request(request: &'r Request) -> RequestOutcome<Self, Self::Error> {
|
|
|
|
RequestOutcome::success(HeaderCount(request.headers().len()))
|
2016-09-04 20:51:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
fn header_count(header_count: HeaderCount) -> String {
|
|
|
|
format!("Your request contained {} headers!", header_count)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2016-10-04 02:48:33 +00:00
|
|
|
rocket::ignite().mount("/", routes![header_count]).launch()
|
2016-09-04 20:51:16 +00:00
|
|
|
}
|