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)
}
我应该怎么改呢?
1
共 4 条评论, 1 页
评论区
写评论发错了,是这个tower_http::decompression::Decompression
--
👇
joshua86z: 新的问题 .layer(RequestDecompressionLayer::new()) 报错 the trait
From<Box<(dyn StdError + std::marker::Send + std::marker::Sync + 'static)>>
is not implemented forInfallible
--
👇
Bai-Jinlin: 你是不是再找 https://docs.rs/tower-http/0.4.0/tower_http/decompression/struct.RequestDecompressionLayer.html
底层都是hyper应该差不多
👇
langzi.me: reqwest包里有类似的处理。我做http代理的时候参考过
reqwest包里有类似的处理。我做http代理的时候参考过
你是不是再找 https://docs.rs/tower-http/0.4.0/tower_http/decompression/struct.RequestDecompressionLayer.html