reqwest-middleware
reqwest-middleware copied to clipboard
Use http::Request::extensions
Motivations
This is a random thought, but it might be worth tracking.
We have task-local-extensions to provide a type agnostic data for middlewares. http::Request also has their own.
Solution
By building with http::Request instead of reqwest::Request, we can reuse their extensions and simplify our own code and get more ecosystem support. There is a TryFrom between the two and it should in theory never fail (the only difference is the Url types. But they should both be spec compliant).
Also, we would lose the extensions when sending through the conversion, so I propose we wrap the Response type to store the state of the extensions at the end
Doesn't our current extension span both the response and the request?
If you use the Builder::send()
mechanism, the extension is lost. If you use the execute_with_extension()
, you can keep it around. We used to have a send_with_extensions
, but I removed it to embed the extensions within the RequestBuilder
to allow the RequestInitialiser
functionality to insert extensions eagerly