< 返回版块

joshua86z 发表于 2023-04-14 17:01

Tags:axum

async fn my_api(Json<v>: Json<MyData>) -> Result<Json<MyData>, AppError> {
////
}

let app = Router::new().route("/api", post(my_api);

但是有可能请求 body 是用 gzip 压缩过的 想写个中间件 如果 header里有 "content-encoding": "gzip" 就能自动解压数据 官方例子是

 async fn my_gzip<B>(mut req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> {
   // 怎么操作??
   Ok(next.run(req).await)
 }

我应该怎么改呢?

评论区

写评论
Bai-Jinlin 2023-04-22 10:18

发错了,是这个tower_http::decompression::Decompression

--
👇
joshua86z: 新的问题 .layer(RequestDecompressionLayer::new()) 报错 the trait From<Box<(dyn StdError + std::marker::Send + std::marker::Sync + 'static)>> is not implemented for Infallible

--
👇
Bai-Jinlin: 你是不是再找 https://docs.rs/tower-http/0.4.0/tower_http/decompression/struct.RequestDecompressionLayer.html

langzi.me 2023-04-15 13:12

底层都是hyper应该差不多

👇
langzi.me: reqwest包里有类似的处理。我做http代理的时候参考过

langzi.me 2023-04-15 13:11

reqwest包里有类似的处理。我做http代理的时候参考过

Bai-Jinlin 2023-04-14 21:10

你是不是再找 https://docs.rs/tower-http/0.4.0/tower_http/decompression/struct.RequestDecompressionLayer.html

1 共 4 条评论, 1 页