7 releases
Uses old Rust 2015
0.3.3 | Sep 7, 2017 |
---|---|
0.3.2 | Aug 26, 2017 |
0.3.0 | Jun 29, 2017 |
0.2.1 | Mar 30, 2017 |
0.1.0 | Mar 2, 2017 |
#905 in #tokio
38 downloads per month
Used in swindon
24KB
422 lines
Httpbin in Rust
Status: | Alpha |
---|
This is a reimplementation of httpbin for two purposes:
- To demonstrate (and test) abilities of a http library for rust
- To make a static binary providing all the httpbin functionality
(not affiliated to the original httpbin)
Installation (of the binary):
cargo install httpbin
Or use it as a library
License
Licensed under either of
- Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
A http bin library embeddable to any tk-http
application
Use HttpBin
as a factory and HttpBin::instantiate
to create
tk_http::server::Dispatcher
.
Example
extern crate tokio_core;
extern crate futures;
extern crate tk_http;
extern crate tk_listen;
extern crate httpbin;
use std::time::Duration;
use tokio_core::reactor::Core;
use tokio_core::net::{TcpListener};
use futures::{Stream, Future};
use httpbin::HttpBin;
use tk_http::server::{Config, Proto};
use tk_listen::ListenExt;
let mut lp = Core::new().unwrap();
let addr = "0.0.0.0:8080".parse().unwrap();
let listener = TcpListener::bind(&addr, &lp.handle()).unwrap();
let cfg = Config::new().done();
let bin = HttpBin::new();
let h1 = lp.handle();
let done = listener.incoming()
.sleep_on_error(Duration::from_millis(100), &h1)
.map(move |(socket, addr)| {
Proto::new(socket, &cfg, bin.instantiate(addr), &h1)
.map_err(|e| { println!("Connection error: {}", e); })
})
.listen(1000);
lp.run(done).unwrap();
Dependencies
~13MB
~255K SLoC