#iron #vhost

iron_vhosts

An Iron addon to allow requests to be routed based on the host

5 releases (3 breaking)

Uses old Rust 2015

0.5.0 Jan 19, 2017
0.4.1 Dec 26, 2016
0.4.0 Dec 11, 2016
0.2.0 May 27, 2016
0.1.0 May 5, 2015

#1212 in HTTP server

Custom license

4KB

Iron Vhosts

Vhost handler for the Iron web framework.

Example

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();
}

Installation

If you're using cargo, just add iron_vhosts to your Cargo.toml.

[dependencies]

iron_vhosts = "*"

Dependencies

~4.5MB
~113K SLoC