OxHTTP
OxHTTP is a very simple synchronous implementation of HTTP 1.1 in Rust. It provides both a client and a server.
Client
OxHTTP provides a very simple client. It aims at following the basic concepts of the Web Fetch standard without the bits specific to web browsers (context, CORS...).
HTTPS is supported behind the disabled by default native-tls
feature.
Example:
let client = Client::new();
let response = client.request(Request::new(Method::GET, "http://example.com".parse()?))?;
Server
OxHTTP provides a very simple threaded HTTP server. It is still a work in progress. Use at your own risks!
Example:
// Builds a new server that returns a 404 everywhere except for "/" where it returns the body 'home' "/
let mut server = Server::new(|request| {
if request.url().path() == "/" {
Response::new(Status::OK).with_body("home")
} else {
Response::new(Status::NOT_FOUND)
}
});
// Raise a timeout error if the client does not respond after 10s.
server.set_global_timeout(Some(Duration::from_secs(10)));
// Listen to localhost:8080
server.listen(("localhost", 8080))?;
License
This project is 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 Futures by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.