Add proxy middleware with circuit breaker fallback#177
Add proxy middleware with circuit breaker fallback#177timvw wants to merge 1 commit intodeborahgu:mainfrom
Conversation
Smart proxy to Bose servers with automatic fallback to local handlers. Controlled via SOUNDCORK_MODE env var (default: local). - ProxyMiddleware intercepts /marge, /bmx, /updates prefixes - Circuit breaker per upstream server (opens on errors/404/5xx) - 5-minute cooldown before retrying failed upstreams - Traffic logging to JSONL file - Adds httpx dependency Addresses deborahgu#152
|
We really appreciate contributions to research the Bose APIs. However the tooling to achieve this is currently not limiting us. We need more people testing and documenting the API bits and pieces that are missing or not working because they are not (or only partially) implemented by soundcork. So if your tooling helps you to do this please go ahead, use it and come back with your API communication captures to specify what should be implemented or fixed in soundcork. It is also important that we document the requests to the device that trigger those Bose server APIs calls. Check this example API Spec for "remove-preset" #146. |
|
Thanks for the feedback — fair point. The real value is in the API specs, not the tooling itself. We've been using tshark/Wireshark to capture and research the Spotify-related traffic and documented our findings in #107. Following the format from #146, we've filed #199 for the Spotify OAuth token refresh endpoint ( We'll continue capturing traffic and filing API specs for any other missing endpoints we find. The proxy is useful for our own research; we'll focus contributions on the specs and implementations. |
Summary
Adds a smart proxy middleware that can forward requests to the real Bose servers with automatic fallback to soundcork's local handlers.
Addresses #152
How it works
A new
ProxyMiddleware(Starlette middleware) intercepts requests matching known Bose path prefixes:/marge/*https://streaming.bose.com/bmx/*https://content.api.bose.io/updates/*https://worldwide.bose.comModes (controlled by
SOUNDCORK_MODEenv var):local(default) — all requests handled locally, middleware is a no-opproxy— tries upstream first, falls back to local on failureCircuit breaker tracks upstream health per-server:
Traffic logging in proxy mode — JSONL file with full request/response details.
Files changed
soundcork/proxy.py— middleware + circuit breaker + loggingsoundcork/config.py— addssoundcork_modeandsoundcork_log_dirsettingssoundcork/main.py— registers the middlewarerequirements.txt— addshttpx==0.28.1Why this is useful
Recommendation
Default mode is
local(middleware does nothing). I'd recommend keepinglocalas default for production since the marge server's/streaming/software/update/endpoint could potentially push firmware updates.