Struct iron_vhosts::Vhosts
[−]
[src]
pub struct Vhosts { /* fields omitted */ }
Methods
impl Vhosts
[src]
fn new<H: Handler>(h: H) -> Vhosts
fn add_host<H: Handler, I: Into<String>>(
&mut self,
host: I,
h: H
) -> Option<Box<Handler>>
&mut self,
host: I,
h: H
) -> Option<Box<Handler>>
For adding a handler for a host
Examples
extern crate iron; extern crate iron_vhosts; use iron::prelude::*; use iron::status; use iron_vhosts::Vhosts; fn main () { //Default handler passed to new let mut vhosts = Vhosts::new(|_: &mut Request| Ok(Response::with((status::Ok, "vhost")))); //Add any host specific handlers vhosts.add_host("localhost", localhost_handler); vhosts.add_host("media.localhost", media_handler); fn localhost_handler(_: &mut Request) -> IronResult<Response> { Ok(Response::with((status::Ok, "localhost"))) } fn media_handler(_: &mut Request) -> IronResult<Response> { Ok(Response::with((status::Ok, "media"))) } Iron::new(vhosts).http("localhost:3000").unwrap(); }
Trait Implementations
impl Handler for Vhosts
[src]
fn handle(&self, req: &mut Request) -> IronResult<Response>
Produce a Response
from a Request, with the possibility of error.