diff options
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/bin/fatcat-iron.rs | 8 | ||||
| -rw-r--r-- | rust/src/lib.rs | 21 | 
2 files changed, 22 insertions, 7 deletions
| diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs index eed98b1d..0bed0fa2 100644 --- a/rust/src/bin/fatcat-iron.rs +++ b/rust/src/bin/fatcat-iron.rs @@ -8,10 +8,8 @@ extern crate futures;  extern crate iron;  extern crate iron_slog;  extern crate swagger; -#[macro_use] -extern crate error_chain; -#[macro_use] -extern crate slog; +#[macro_use] extern crate error_chain; +#[macro_use] extern crate slog;  extern crate slog_term;  extern crate slog_async; @@ -50,6 +48,8 @@ fn main() {      // for the purpose of this example, pretend we have authenticated a user      chain.link_before(AllowAllMiddleware::new("cosmo")); +    chain.link_after(fatcat::XClacksOverheadMiddleware); +      if matches.is_present("https") {          unimplemented!()      } else { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index fbff6ab2..55040f0c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -4,10 +4,10 @@ extern crate chrono;  extern crate diesel;  extern crate dotenv;  extern crate futures; -extern crate hyper; +#[macro_use] extern crate hyper;  extern crate swagger; -#[macro_use] -extern crate error_chain; +#[macro_use] extern crate error_chain; +extern crate iron;  pub mod api_server; @@ -20,6 +20,9 @@ use diesel::pg::PgConnection;  use diesel::prelude::*;  use dotenv::dotenv;  use std::env; +use hyper::header::Headers; +use iron::{Request, Response}; +use iron::middleware::AfterMiddleware;  pub fn establish_connection() -> PgConnection {      dotenv().ok(); @@ -32,3 +35,15 @@ pub fn establish_connection() -> PgConnection {  pub fn server() -> Result<api_server::Server> {      Ok(api_server::Server {})  } + +/// HTTP header middleware +header! { (XClacksOverhead, "X-Clacks-Overhead") => [String] } + +pub struct XClacksOverheadMiddleware; + +impl AfterMiddleware for XClacksOverheadMiddleware { +    fn after(&self, _req: &mut Request, mut res: Response) -> iron::IronResult<Response> { +        res.headers.set(XClacksOverhead("GNU aaronsw, jpb".to_owned())); +        Ok(res) +    } +} | 
