oxidecomputer / progenitor

An OpenAPI client generator
426 stars 55 forks source link

add mut request `pre_hook` #823

Closed drahnr closed 1 month ago

drahnr commented 1 month ago

Currently progenitor supports pre_hook, pre_hook_async and post_hook, where the further get a &reqwest::Request passed. The auth mechanism for an OpenAPI spec requires to sign the encoded query and append two key value pairs to the request, as such the pre-hook appears to be the right place to adjust the Request accordingly.

Proposal:

Add with_pre_hook_mut in addition, allowing to modify the Request accordingly.

Considerations:

Since it's a per-request signature, modifying the Client itself is not sufficient.

Altneratives:

Change the API of the current pre_hook to take a &mut and use lint exception to avoid getting warnings on existing code.

jclulow commented 1 month ago

FWIW, when I added pre_hook_async it was also for signing requests in a similar manner, and as such already gets a mutable reference to the request.

drahnr commented 1 month ago

FWIW, when I added pre_hook_async it was also for signing requests in a similar manner, and as such already gets a mutable reference to the request.

I'd be in favor to closing this PR and changing the sync hook API to take a &mut Request.