http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

Middleware for global shared client? #259

Closed aldanor closed 3 years ago

aldanor commented 3 years ago

IIUC, there's no way to push anything onto the global client's middleware stack (aside from hardcoded logger middleware here, which serves more as an example since most users will prefer to do tracing/logging in their own way).

This means you have to choose - global/default client but no middleware, or having to pull your own client instance around just for the sake of having access to middleware, even if you use the same middleware stack everywhere?

Alternative formulation: would there be a way for surf::get(), surf::post(), etc, to make use of custom middleware?

Fishrock123 commented 3 years ago

If this happened, it would be per-RequestBuilder middleware.

Otherwise, you should make your own global client with either once_cell::sync::Lazy or lazy_static!.