06chaynes / http-cache

A caching middleware that follows HTTP caching rules
https://http-cache.rs/
Apache License 2.0
69 stars 17 forks source link

allow mode override by reqwest-middleware extension #66

Closed matt-phylum closed 10 months ago

matt-phylum commented 10 months ago

This PR allows users of http-cache-reqwest to override the cache mode on a per-request basis using reqwest-middleware's extension mechanism. For cache_mode_fn, the request parts need to have some recognizable characteristic that is known ahead of time, or the cache_mode_fn implementation needs to have some shared mutable state that allows recognizable requests to be registered on the fly. With request extensions, the caller can simply specify something like .with_extension(CacheMode::Reload) when building the request and just that request will be affected, even if it has the exact same parts as another request.

Other middleware implementations can implement a similar feature by providing an implementation for the new overridden_cache_mode function, but I don't know of an equivalent capability for surf so I didn't implement this feature there.

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (937e587) 92.64% compared to head (9b0ff54) 92.90%. Report is 5 commits behind head on develop.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #66 +/- ## =========================================== + Coverage 92.64% 92.90% +0.25% =========================================== Files 11 11 Lines 1101 1141 +40 =========================================== + Hits 1020 1060 +40 Misses 81 81 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

06chaynes commented 10 months ago

Nice, looks great! Thanks again for the contribution