[PR #528] [MERGED] feat: Add support for reqwest-middleware #516

Closed
opened 2026-02-27 20:25:01 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/528
Author: @lazulit3
Created: 6/11/2025
Status: Merged
Merged: 6/17/2025
Merged by: @ramsayleung

Base: masterHead: master


📝 Commits (6)

  • 2eace79 feat: Add support for reqwest-middleware
  • 0ca08d2 style(rspotify-http): fix fmt lint, sort re-exports
  • 321edff fix(rspotify-http): disable lint based on feat flag
  • fc6c370 test(rspotify-http): add test for reqwest-middleware
  • d83ebc5 style(rspotify-http): remove accidental diff (space)
  • 6f19ab2 refactor(rspotify-http): clarify feat-gated imports

📊 Changes

7 files changed (+213 additions, -18 deletions)

View changed files

📝 Cargo.toml (+3 -0)
📝 rspotify-http/Cargo.toml (+6 -0)
📝 rspotify-http/src/lib.rs (+3 -0)
📝 rspotify-http/src/reqwest.rs (+147 -18)
📝 src/auth_code.rs (+18 -0)
📝 src/auth_code_pkce.rs (+18 -0)
📝 src/client_creds.rs (+18 -0)

📄 Description

Description

Adds a reqwest-middleware feature flag to rspotify-http and rspotify. When enabled, this will:

  • Export additional types from rspotify-http that would allow the library to build a client with middleware
  • Expose with_middleware and with_middleware_arc for adding middleware to each rspotify client

Motivation and Context

I am interested in using http-cache-reqwest to cache my API responses using ETags provided in Spotify API responses. Adding support for middleware would allow users to construct their rspotify clients with caching or other middlewares.

Dependencies

This doesn't depend on other changes.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this been tested?

A test has been added to the PR.

I have not tested this beyond using it in a personal project.
I have used this successfully in a personal project for caching. Here's an example of usage:

        let cache = Arc::new(Cache(HttpCache {
            mode: CacheMode::Default,
            manager: CACacheManager {
                path: PathBuf::from(".cache"),
            },
            options: HttpCacheOptions {
                cache_options: Some(CacheOptions {
                    shared: false,
                    ..Default::default()
                }),
                ..Default::default()
            },
        }));
        let oauth_client =
            AuthCodePkceSpotify::with_config(creds, oauth, config).with_middleware_arc(cache);

I've verified that my middleware (caching) works by inspecting my API responses using a local proxy (Proxyman). This verifies that the middleware is used.

Is this change properly documented?

No, sorry. Would love help! (Non-maintainers are welcome to PR against my branch.)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/528 **Author:** [@lazulit3](https://github.com/lazulit3) **Created:** 6/11/2025 **Status:** ✅ Merged **Merged:** 6/17/2025 **Merged by:** [@ramsayleung](https://github.com/ramsayleung) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (6) - [`2eace79`](https://github.com/ramsayleung/rspotify/commit/2eace794e0b80374aff6ee0431361942409e900c) feat: Add support for `reqwest-middleware` - [`0ca08d2`](https://github.com/ramsayleung/rspotify/commit/0ca08d2fe2e5db38fe652fc0f62725ff3c9d5eaa) style(rspotify-http): fix fmt lint, sort re-exports - [`321edff`](https://github.com/ramsayleung/rspotify/commit/321edff1fab89435ed97d6d7a1f23f6d71b946fa) fix(rspotify-http): disable lint based on feat flag - [`fc6c370`](https://github.com/ramsayleung/rspotify/commit/fc6c37080060282025e97322e8853d56b0ad3998) test(rspotify-http): add test for reqwest-middleware - [`d83ebc5`](https://github.com/ramsayleung/rspotify/commit/d83ebc56953109e91ec75850cf81c03c57d61d0e) style(rspotify-http): remove accidental diff (space) - [`6f19ab2`](https://github.com/ramsayleung/rspotify/commit/6f19ab22e5f93ac378987a1f8524ab18f112a9a8) refactor(rspotify-http): clarify feat-gated imports ### 📊 Changes **7 files changed** (+213 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.toml` (+3 -0) 📝 `rspotify-http/Cargo.toml` (+6 -0) 📝 `rspotify-http/src/lib.rs` (+3 -0) 📝 `rspotify-http/src/reqwest.rs` (+147 -18) 📝 `src/auth_code.rs` (+18 -0) 📝 `src/auth_code_pkce.rs` (+18 -0) 📝 `src/client_creds.rs` (+18 -0) </details> ### 📄 Description ## Description - https://github.com/ramsayleung/rspotify/issues/527 Adds a `reqwest-middleware` feature flag to `rspotify-http` and `rspotify`. When enabled, this will: - Export additional types from `rspotify-http` that would allow the library to build a client with middleware - Expose `with_middleware` and `with_middleware_arc` for adding middleware to each rspotify client ## Motivation and Context I am interested in using [http-cache-reqwest](https://crates.io/crates/http-cache-reqwest) to cache my API responses using ETags provided in Spotify API responses. Adding support for middleware would allow users to construct their `rspotify` clients with caching or other middlewares. ## Dependencies This doesn't depend on other changes. ## Type of change Please delete options that are not relevant. - [X] New feature (non-breaking change which adds functionality) ## How has this been tested? A test has been added to the PR. ~~I have not tested this beyond using it in a personal project.~~ I have used this successfully in a personal project for caching. Here's an example of usage: ```rust let cache = Arc::new(Cache(HttpCache { mode: CacheMode::Default, manager: CACacheManager { path: PathBuf::from(".cache"), }, options: HttpCacheOptions { cache_options: Some(CacheOptions { shared: false, ..Default::default() }), ..Default::default() }, })); let oauth_client = AuthCodePkceSpotify::with_config(creds, oauth, config).with_middleware_arc(cache); ``` I've verified that my middleware (caching) works by inspecting my API responses using a local proxy (Proxyman). This verifies that the middleware is used. ## Is this change properly documented? No, sorry. **Would love help!** (Non-maintainers are welcome to PR against my branch.) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:25:01 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#516
No description provided.