Replies: 1 comment
-
Pew, using the middleware crate seems also not like an option since of course as it wraps use reqwest::{Request, Response};
use reqwest_middleware::ClientBuilder;
use reqwest_middleware::{Middleware, Next};
use task_local_extensions::Extensions;
struct OriginalHeadersMiddleware;
#[async_trait::async_trait]
impl Middleware for OriginalHeadersMiddleware {
async fn handle(
&self,
req: Request,
extensions: &mut Extensions,
next: Next<'_>,
) -> reqwest_middleware::Result<Response> {
let resp = next.run(req, extensions).await?;
dbg!(resp.headers());
Ok(resp)
}
}
#[tokio::main]
async fn main() {
let rc = reqwest::ClientBuilder::new().gzip(true).build().unwrap();
let client = ClientBuilder::new(rc)
.with(OriginalHeadersMiddleware)
.build();
let resp = client.get("https://httpbin.org/gzip").send().await.unwrap();
dbg!(&resp);
let text = resp.text().await;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I use
reqwest
to transfer large amounts of verbose JSON which should compress just fine.For some reason, I would like to measure the actual transferred bytes and therefore I am interested in the
Content-Length
of the compressed response.I understand that the header is removed due to automatic handling via the
gzip()
client option.Is there a way for me to get the number I am interested in? I thought about not using
.gzip()
and instead decode myself, but browsing through the source I doubt that I can implement this as good as it's implemente inreqwest
.Do I need something like this middleware crate to accomplish this or is there a simpler option?
Thanks,
Philipp
Beta Was this translation helpful? Give feedback.
All reactions