OxHTTP is a simple and naive synchronous implementation of HTTP 1.1 in Rust. It provides both a client and a server. It does not aim to be a fully-working-in-all-cases HTTP implementation but to be only a naive one to be use in simple usecases.
OxHTTP provides a 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 (to use the current system native implementation) or rustls
feature (to use Rustls).
Example: ```rust use oxhttp::Client; use oxhttp::model::{Request, Method, Status, HeaderName}; use std::io::Read;
let client = Client::new(); let response = client.request(Request::builder(Method::GET, "http://example.com".parse().unwrap()).build()).unwrap(); asserteq!(response.status(), Status::OK); asserteq!(response.header(&HeaderName::CONTENTTYPE).unwrap().asref(), b"text/html; charset=UTF-8");
let body = response.intobody().tostring().unwrap(); ```
OxHTTP provides a threaded HTTP server. It is still a work in progress. Use at your own risks behind a reverse proxy!
Example: ```rust no_run use oxhttp::Server; use oxhttp::model::{Response, Status}; use std::time::Duration;
// 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::builder(Status::OK).withbody("home") } else { Response::builder(Status::NOTFOUND).build() } }); // Raise a timeout error if the client does not respond after 10s. server.setglobaltimeout(Duration::from_secs(10)); // Listen to localhost:8080 server.listen(("localhost", 8080)).unwrap(); ```
This project is licensed under either of
<http://www.apache.org/licenses/LICENSE-2.0>
)<http://opensource.org/licenses/MIT>
)at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in OxHTTP by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.