9 releases

Uses old Rust 2015

0.4.0 Nov 26, 2018
0.3.2 Jan 11, 2017
0.3.1 Dec 5, 2016
0.2.1 Oct 8, 2016
0.1.1 May 25, 2016

#1406 in HTTP server

26 downloads per month

MIT license

6KB
94 lines

limiter

Build Status

This is an example of BeforeMiddleware for the Iron framework. It limits the request body size by checking first the Content-Length header, then the size of the payload. The response is either an HTTP 413 or it continues down the chain.

It will also set an upper bound on the length of a URL which can be helpful in regular GET requests.

Include this in your Cargo.toml file:

[dependencies]
limiter = "0.3"

Documentation

https://docs.rs/limiter

Example

extern crate iron;
extern crate limiter;

use iron::prelude::*;

use limiter::RequestLimit;

fn index(_: &mut Request) -> IronResult<Response> {
    Ok(Response::with((iron::status::Ok, "Test")))
}

fn main() {
    let max_request = RequestLimit::default();
    let mut chain = Chain::new(index);
    chain.link_before(max_request);
    Iron::new(chain).http("localhost:3000").unwrap();
}

License

MIT

Dependencies

~4.5MB
~114K SLoC