#reqwest-middleware #disable #wrapper #basis #wrapped #conditional #per-request

reqwest-conditional-middleware

一个中间件包装器,根据每个请求启用(或禁用)包装的 Reqwest 中间件

4 个版本 (2 个重大更新)

0.3.0 2024 年 5 月 29 日
0.2.1 2023 年 5 月 5 日
0.2.0 2023 年 5 月 5 日
0.1.0 2022 年 6 月 23 日

#71 in HTTP 服务器

Download history 4858/week @ 2024-04-15 6464/week @ 2024-04-22 5508/week @ 2024-04-29 5039/week @ 2024-05-06 4641/week @ 2024-05-13 5901/week @ 2024-05-20 4515/week @ 2024-05-27 4668/week @ 2024-06-03 4435/week @ 2024-06-10 6482/week @ 2024-06-17 5936/week @ 2024-06-24 3431/week @ 2024-07-01 3833/week @ 2024-07-08 3622/week @ 2024-07-15 3994/week @ 2024-07-22 4399/week @ 2024-07-29

15,952 每月下载量
用于 24 个 Crates(20 个直接使用)

MIT 许可证

9KB
117

reqwest-conditional-middleware

CI docs.rs

一个中间件包装器,根据每个请求启用(或禁用)包装的 Reqwest 中间件

示例

使用此包依赖于几个其他包

async-trait = "0.1.80"
http = "1"
reqwest = version = "0.12"
reqwest-conditional-middleware = "0.3.0"
reqwest-middleware = "0.3"

这是一个条件中间件的示例,它会在请求方法为 GET 时短路中间件堆栈并返回 OK

use reqwest::{Request, Response};
use reqwest_conditional_middleware::ConditionalMiddleware;
use reqwest_middleware::{Middleware, Next, Result};
use task_local_extensions::Extensions;

struct AlwaysOk;

#[async_trait::async_trait]
impl Middleware for AlwaysOk {
    async fn handle(
        &self,
        _req: Request,
        _extensions: &mut Extensions,
        _next: Next<'_>,
    ) -> Result<Response> {
        let builder = http::Response::builder().status(http::StatusCode::OK);
        Ok(builder.body("").unwrap().into())
    }
}

let conditional = ConditionalMiddleware::new(
    AlwaysOk,
    |req: &Request| req.method() == http::Method::GET
);

依赖项

~4–14MB
~201K SLoC