#iron #request #drain

iron-drain

Iron middleware that makes sure requests are read in full before reusing sockets

3 releases

Uses old Rust 2015

0.1.2 Jan 20, 2017
0.1.1 Apr 2, 2016
0.1.0 Apr 2, 2016

#17 in #drain

MIT license

4KB

This is a tiny Rust crate containing an Iron middleware. The middleware serves to work around a bug in hyper that can cause sockets to be reused without the previous request being fully read out, which always causes the next request to fail in parsing.

For usage, see the documentation.


lib.rs:

Iron middleware that makes sure requests are read in full before reusing sockets

Hyper keeps sockets alive to reuse them between requests, to speed things up. If a request that isn't supposed to have a body is sent with one, or if the server does not read out the full body of a request, then the next request will be corrupted due to data remaining in the network buffer.

The Drain adapter in this module defines an iron AfterMiddleware that makes sure to empty the buffer before the next request, whether the current request succeeded or failed. It reads up to a configurable limit, and if there is still more data remaining, it closes the socket.

Usage:

extern crate iron;
extern crate iron_drain;

use iron::prelude::*;
use iron::status;
use iron_drain::Drain;

let mut srv = Chain::new(|_: &mut Request| {
    Ok(Response::with((status::Ok, "Hello world!")))
});
srv.link_after(Drain::new());
Iron::new(srv).http("localhost:3000").unwrap();

Dependencies

~6MB
~122K SLoC