reqwest-middleware icon indicating copy to clipboard operation
reqwest-middleware copied to clipboard

Use http::Request::extensions

Open conradludgate opened this issue 2 years ago • 2 comments

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

conradludgate avatar Nov 23 '22 22:11 conradludgate

Doesn't our current extension span both the response and the request?

LukeMathWalker avatar Nov 24 '22 09:11 LukeMathWalker

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

conradludgate avatar Nov 24 '22 09:11 conradludgate