2个不稳定版本

0.2.0 2024年5月19日
0.1.0 2023年9月29日

#247 in HTTP客户端

Download history 106/week @ 2024-04-22 89/week @ 2024-04-29 123/week @ 2024-05-06 188/week @ 2024-05-13 159/week @ 2024-05-20 96/week @ 2024-05-27 134/week @ 2024-06-03 116/week @ 2024-06-10 91/week @ 2024-06-17 89/week @ 2024-06-24 96/week @ 2024-07-01 90/week @ 2024-07-08 133/week @ 2024-07-15 86/week @ 2024-07-22 107/week @ 2024-07-29 69/week @ 2024-08-05

每月402次下载

MIT许可证

5KB

reqwest-leaky-bucket

leaky-bucket基于reqwest-ratelimit的速率限制中间件实现,用于reqwest-middleware

Crates.io Docs.rs

用法

use async_trait::async_trait;
use reqwest_leaky_bucket::leaky_bucket::RateLimiter;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};

async fn run() {
    let limiter = RateLimiter::builder().max(10).initial(0).refill(5).build();
    let client = ClientBuilder::new(reqwest::Client::new())
        .with(reqwest_leaky_bucket::rate_limit_all(limiter))
        .build();
    client.get("https://crates.io").send().await.unwrap();
}

lib.rs:

基于reqwest_middlewarereqwest_ratelimitleaky_bucket构建的请求速率限制中间件。

leaky_bucket::RateLimiter提供reqwest_ratelimit::RateLimiter适配器。

示例

use async_trait::async_trait;
use reqwest_leaky_bucket::leaky_bucket::RateLimiter;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};

async fn run() {
    let limiter = RateLimiter::builder().max(10).initial(0).refill(5).build();

    let client = ClientBuilder::new(reqwest::Client::new())
        .with(reqwest_leaky_bucket::rate_limit_all(limiter))
        .build();

    client.get("https://crates.io").send().await.unwrap();
}

依赖

~6–18MB
~243K SLoC