File: iron_intercept.rs

package info (click to toggle)
rust-multipart 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 416 kB
  • sloc: makefile: 2; sh: 1
file content (25 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
extern crate iron;
extern crate multipart;

use iron::prelude::*;

use multipart::server::Entries;
use multipart::server::iron::Intercept;

fn main() {
    // We start with a basic request handler chain.
    let mut chain = Chain::new(|req: &mut Request|
        if let Some(entries) = req.extensions.get::<Entries>() {
            Ok(Response::with(format!("{:?}", entries)))
        } else {
            Ok(Response::with("Not a multipart request"))
        }
    );

    // `Intercept` will read out the entries and place them as an extension in the request.
    // It has various builder-style methods for changing how it will behave, but has sane settings
    // by default.
    chain.link_before(Intercept::default());

    Iron::new(chain).http("localhost:80").unwrap();
}