Skip to main content

Crate reqres

Crate reqres 

Source
Expand description

§reqres

reqres 是一个纯 Rust 实现的异步 HTTP 客户端库,基于 Tokio 运行时构建。

§特性

  • 完整协议支持:HTTP/1.1、HTTP/2
  • 🚀 高性能:连接池、异步 I/O、零拷贝
  • 🔒 HTTPS 支持:基于 Rustls 的 TLS 实现
  • 🍪 Cookie 管理:自动存储和发送
  • 🗜️ 压缩支持:gzip、deflate、brotli 自动解压
  • 🔌 代理支持:HTTP/HTTPS/SOCKS5 代理配置
  • 🎯 易用 API:Builder 模式、链式调用

§快速开始

use reqres::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new()?;

    // GET 请求
    let response = client.get("https://httpbin.org/get").await?;
    println!("{}", response.text()?);

    Ok(())
}

§高级用法

use reqres::{Client, CookieJar};

let mut cookie_jar = CookieJar::new();
cookie_jar.insert("session".to_string(), "abc123".to_string());

let client = Client::builder()
    .cookie_jar(cookie_jar)
    .build()?;

§压缩支持

use reqres::Client;

let client = Client::builder()
    .enable_compression()
    .build()?;

§连接池

use reqres::Client;

let client = Client::builder()
    .enable_pooling()
    .build()?;

§性能

  • 连接池:20-25% 性能提升
  • Cookie 操作:纳秒级(50-700 ns)
  • HTTP/2:15-20% 并发性能提升

运行基准测试:cargo bench

§版本历史

  • v0.7.0 - 性能基准测试 + 文档完善
  • v0.6.0 - 高级功能(代理、Cookie、压缩)
  • v0.4.0 - 连接池 + 性能优化
  • v0.3.0 - HTTP/2 支持
  • v0.2.0 - HTTPS + Builder 模式
  • v0.1.0 - 基础 HTTP/1.1 客户端

§许可证

MIT

Re-exports§

pub use client::Client;
pub use client::ClientBuilder;
pub use compression::CompressionEncoding;
pub use compression::Decompressor;
pub use cookie::CookieJar;
pub use error::ReqresError;
pub use error::Result;
pub use proxy::Proxy;
pub use proxy::ProxyBuilder;
pub use proxy::ProxyType;
pub use request::Request;
pub use request::RequestBuilder;
pub use request::Method;
pub use response::Response;
pub use serde_json;

Modules§

client
HTTP 客户端
compression
压缩和解压缩
cookie
Cookie 管理
error
pool
proxy
代理配置
request
response