I/O-free Rust library to send HTTP requests, based on stream-flows.
This library does not perform any I/O. Instead, it exposes I/O-free, composable and iterable state machines so called flows.
A flow emits I/O requests, which should be processed by I/O handlers. A flow is considered terminated when it does not emit I/O requests anymore.
HTTP flows emit stream I/O requests defined by the stream-flows crate, so any I/O stream handler should work.
See complete examples at ./examples.
use std::{net::TcpStream, sync::Arc};
use http_flows::{flows::Send, Request};
use rustls::{ClientConfig, ClientConnection, StreamOwned};
use rustls_platform_verifier::ConfigVerifierExt;
use stream_flows::handlers::std::Handler;
// build TLS stream
let domain = "github.com"
let config = ClientConfig::with_platform_verifier();
let server_name = domain.to_string().try_into().unwrap();
let conn = ClientConnection::new(Arc::new(config), server_name).unwrap();
let tcp = TcpStream::connect((domain, 443)).unwrap();
let tls = StreamOwned::new(conn, tcp);
// send request send receive response
let request = Request::new("GET", "/", "1.0").body("");
let mut send = Send::new(request);
let response = loop {
match send.next() {
Ok(response) => break response,
Err(io) => Handler::handle(&mut stream, &mut send, io).unwrap(),
}
};
See complete example at ./examples/send.rs.
cargo run --example send
Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from various programs:
- NGI Assure in 2022
- NGI Zero Entrust in 2023
- NGI Zero Core in 2024 (still ongoing)
If you appreciate the project, feel free to donate using one of the following providers: