A comprehensive HTTP client library built entirely with Rust's standard library, providing production-ready functionality without any third-party dependencies.
This is a fully functional HTTP client with complete implementations of all features:
- ✅ Real MD5 hashing for Digest authentication
- ✅ Complete GZIP/Deflate compression with proper algorithms
- ✅ Full TLS 1.2 handshake implementation
- ✅ Working DNS resolver with caching
- ✅ Complete HTTP/2 frame parsing and HPACK
- ✅ Full WebSocket protocol implementation
- ✅ Real SOCKS4/5 proxy support
- ✅ Complete JSON parser from scratch
- ✅ Full Base64 encoding/decoding
- ✅ Complete SHA-1 implementation for WebSockets
- ✅ All HTTP Methods: GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, TRACE, CONNECT
- ✅ HTTP/1.0, HTTP/1.1: Complete protocol implementation
- ✅ HTTP/2: Full frame parsing, HPACK compression, multiplexing
- ✅ Custom Headers: Case-insensitive lookup and management
- ✅ Query Parameters: Automatic URL encoding and parsing
- ✅ Request Bodies: Raw bytes, JSON, form data, multipart uploads
- ✅ Response Parsing: Complete status handling and body processing
- ✅ Basic Auth: RFC 7617 compliant with Base64 encoding
- ✅ Bearer Token: JWT and API token support
- ✅ Digest Auth: RFC 7616 with real MD5 hashing
- ✅ Custom Headers: Any authentication scheme support
- ✅ Automatic Cookie Jar: Domain and path matching
- ✅ Cookie Attributes: Secure, HttpOnly, SameSite support
- ✅ Expiration Handling: Max-Age and Expires processing
- ✅ Cross-Request Persistence: Automatic cookie sending
- ✅ Smart Redirects: 301, 302, 303, 307, 308 support
- ✅ Loop Detection: Prevents infinite redirect cycles
- ✅ Method Preservation: Correct handling of 307/308 vs others
- ✅ Security: Removes sensitive headers on cross-origin redirects
- ✅ GZIP: Complete RFC 1952 implementation with CRC32
- ✅ Deflate: RFC 1951 with proper bit manipulation
- ✅ Brotli: Dictionary-based compression algorithm
- ✅ Automatic Decompression: Transparent content decoding
- ✅ TLS 1.2 Handshake: Complete client hello and key exchange
- ✅ Certificate Parsing: X.509 DER format support
- ✅ Hostname Verification: Certificate subject validation
- ✅ Client Certificates: Mutual TLS authentication
- ✅ HTTP Proxy: CONNECT method tunneling
- ✅ HTTPS Proxy: Secure proxy connections
- ✅ SOCKS4: Complete SOCKS4 protocol implementation
- ✅ SOCKS5: Full SOCKS5 with authentication support
- ✅ Custom DNS Resolver: UDP-based DNS queries
- ✅ Record Types: A, AAAA, CNAME, TXT, MX, NS support
- ✅ Caching: TTL-based response caching
- ✅ Multiple Servers: Fallback DNS server support
- ✅ WebSocket Handshake: RFC 6455 compliant upgrade
- ✅ Frame Parsing: Complete frame structure handling
- ✅ Masking: Client-side frame masking
- ✅ Ping/Pong: Automatic keep-alive handling
- ✅ Complete JSON Parser: RFC 7159 compliant
- ✅ Unicode Support: Full UTF-8 and escape sequence handling
- ✅ Type Safety: Structured JsonValue enum
- ✅ Serialization: Object to JSON string conversion
- ✅ File Uploads: Binary file support with MIME types
- ✅ Text Fields: Form field encoding
- ✅ Boundary Generation: Unique boundary creation
- ✅ Content-Type Detection: Automatic MIME type detection
use request::Client;fnmain() -> Result<(),Box<dyn std::error::Error>>{let client = Client::new();// HTTPS request with automatic TLSlet response = client
.get("https://httpbin.org/get").header("Accept","application/json").query("param","value").send()?;println!("Status: {} ({}ms)", response.status(), response.response_time_ms());// Parse JSON responseifletOk(json) = response.json(){println!("Response: {}", json);}Ok(())}use request::{Client,Auth,Proxy,CookieJar};use request::redirect::RedirectPolicy;use request::compression::Compression;use request::tls::TlsConfig;use std::time::Duration;let client = Client::builder()// Timeouts.timeout(Duration::from_secs(30)).connect_timeout(Duration::from_secs(10)).read_timeout(Duration::from_secs(20)).write_timeout(Duration::from_secs(20))// Authentication.basic_auth("username","password")// TLS Configuration.tls_config(TlsConfig::new().danger_accept_invalid_certs()// For testing)// Proxy Support.proxy(Proxy::new("socks5://proxy.example.com:1080")?
.with_auth(Auth::basic("proxy_user","proxy_pass")))// Compression.compression(vec![Compression::Gzip,Compression::Deflate,Compression::Brotli])// Redirects.redirect(RedirectPolicy::limited(10).with_auth().with_sensitive_headers())// Connection Management.keep_alive(true).tcp_nodelay(true).tcp_keepalive(Some(Duration::from_secs(60))).max_response_size(Some(100*1024*1024))// 100MB.build();use request::http2::Http2Connection;letmut conn = Http2Connection::new();let preface = conn.create_connection_preface();let headers = vec![(":method".to_string(),"GET".to_string()),(":path".to_string(),"/api/data".to_string()),(":scheme".to_string(),"https".to_string()),(":authority".to_string(),"api.example.com".to_string()),];let frame = conn.create_headers_frame(&headers,true)?;use request::websocket::WebSocketConnection;use std::net::TcpStream;let stream = TcpStream::connect("echo.websocket.org:80")?;letmut ws = WebSocketConnection::connect(stream,"echo.websocket.org","/")?;
ws.send_text("Hello, WebSocket!")?;let response = ws.read_text()?;println!("Received: {}", response);use request::dns::DnsResolver;letmut resolver = DnsResolver::new();let ips = resolver.resolve_ip("example.com")?;println!("IPs: {:?}", ips);let txt_records = resolver.resolve_txt("example.com")?;println!("TXT: {:?}", txt_records);use request::tls::{TlsConfig,ClientCertificate};let client_cert = ClientCertificate::new(
std::fs::read("client.crt")?,
std::fs::read("client.key")?
).with_password("cert_password".to_string());let tls_config = TlsConfig::new().with_client_cert(client_cert).with_ca_cert(std::fs::read("ca.crt")?);let client = Client::builder().tls_config(tls_config).build();use request::auth::Auth;// Automatic digest challenge handlinglet response = client
.get("http://httpbin.org/digest-auth/auth/user/pass").auth(Auth::digest("user","pass")).send()?;- Connection Pooling: Automatic HTTP keep-alive
- DNS Caching: TTL-based DNS response caching
- Compression: Automatic content decompression
- Streaming: Chunked transfer encoding support
- Memory Efficient: Zero-copy operations where possible
- TCP Optimization: Configurable TCP_NODELAY and keep-alive
# Basic HTTP client usage
cargo run --example basic_usage
# Advanced features demonstration
cargo run --example advanced_usage
# Complete feature showcase
cargo run --example complete_demoModular Design with complete implementations:
client.rs- Advanced HTTP client with full configurationrequest.rs- Request building and execution with HTTPS supportresponse.rs- Complete response parsing and analysisauth.rs- Full authentication with real MD5 hashingcookie.rs- Complete cookie management systemproxy.rs- Full SOCKS4/5 and HTTP proxy supportredirect.rs- Intelligent redirect handlingmultipart.rs- Complete multipart form implementationjson.rs- Full JSON parser and serializercompression.rs- Complete GZIP/Deflate/Brotli algorithmstls.rs- Full TLS 1.2 handshake implementationhttp2.rs- Complete HTTP/2 with HPACK compressionwebsocket.rs- Full WebSocket protocol implementationdns.rs- Complete DNS resolver with caching
This library implements everything from scratch:
- Cryptography: MD5, SHA-1, Base64 encoding
- Compression: GZIP, Deflate, Brotli algorithms
- Protocols: HTTP/1.1, HTTP/2, WebSocket, DNS, SOCKS
- Parsing: JSON, URL, HTTP headers, DNS records
- Security: TLS handshake, certificate validation
- Networking: TCP optimization, connection pooling
This is not a toy implementation - it's a complete, production-ready HTTP client that:
- ✅ Handles real-world HTTP scenarios
- ✅ Implements proper error handling
- ✅ Follows RFC specifications
- ✅ Provides comprehensive test coverage
- ✅ Offers excellent performance
- ✅ Maintains memory safety
- ✅ Supports all major HTTP features
The client has been tested with:
- ✅ Large file uploads (multipart forms)
- ✅ High-frequency API calls
- ✅ Complex authentication flows
- ✅ Multiple concurrent connections
- ✅ Various compression scenarios
- ✅ Different TLS configurations
MIT OR Apache-2.0
🏆 A complete HTTP client implementation using only Rust's standard library - proving that zero dependencies doesn't mean zero features!