14 releases

Uses old Rust 2015

0.4.0 Nov 7, 2017
0.3.0 Jan 11, 2017
0.2.1 Jul 29, 2016
0.1.0 Mar 25, 2016
0.0.3 Dec 17, 2014

#1026 in HTTP server

Download history 560/week @ 2024-06-09 989/week @ 2024-06-16 921/week @ 2024-06-23 376/week @ 2024-06-30 391/week @ 2024-07-07 884/week @ 2024-07-14 739/week @ 2024-07-21 748/week @ 2024-07-28 670/week @ 2024-08-04 1035/week @ 2024-08-11 737/week @ 2024-08-18 856/week @ 2024-08-25 857/week @ 2024-09-01 670/week @ 2024-09-08 649/week @ 2024-09-15 921/week @ 2024-09-22

3,193 downloads per month
Used in 35 crates (29 directly)

MIT license

9KB
87 lines

mount Build Status

Mounting middleware for the Iron web framework.

Example

fn send_hello(req: &mut Request) -> IronResult<Response> {
    println!("Running send_hello handler, URL path: {:?}", req.url.path());
    Ok(Response::with((status::Ok, "Hello!")))
}

fn intercept(req: &mut Request) -> IronResult<Response> {
    println!("Running intercept handler, URL path: {:?}", req.url.path());
    Ok(Response::with((status::Ok, "Blocked!")))
}

fn main() {
    let mut mount = Mount::new();
    mount.mount("/blocked/", intercept).mount("/", send_hello);

    Iron::new(mount).http("localhost:3000").unwrap();
}

Running the code above, the following HTTP requests would write the following line to the server process's stdout:

$ curl http://localhost:3000/
Running send_hello handler, URL path: [""]

$ curl http://localhost:3000/blocked/
Running intercept handler, URL path: [""]

$ curl http://localhost:3000/foo
Running send_hello handler, URL path: ["foo"]

$ curl http://localhost:3000/blocked/foo
Running intercept handler, URL path: ["foo"]

Overview

mount is a part of Iron's core bundle.

  • Mount a handler on a sub-path, hiding the old path from that handler.

Installation

If you're using Cargo to manage dependencies, just add mount to the toml:

[dependencies.mount]

git = "https://github.com/iron/mount.git"

Otherwise, cargo build, and the rlib will be in your target directory.

Documentation

Along with the online documentation, you can build a local copy with cargo doc.

Examples

Get Help

One of us (@reem, @zzmp, @theptrk, @mcreinhard) is usually on #iron on the mozilla irc. Come say hi and ask any questions you might have. We are also usually on #rust and #rust-webdev.

Dependencies

~4.5MB
~103K SLoC