fix: handle HEAD requests on /stream/track/:id endpoint#252
Conversation
Fixes simojenki#229 Sonos devices make HEAD requests to /stream endpoints to check availability and content length without downloading the full track. Previously, only GET requests were handled, causing 401 errors for HEAD requests. Changes: - Extract stream handler into named function streamTrackHandler - Register both GET and HEAD routes to use the same handler - Handler already checks req.method == "GET" to conditionally stream data, so HEAD requests properly return headers without body Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Hi, the PR is ready for review. Thanks! |
|
PR needs test cases so that;
Also, I'm not convinced that loading the entire stream from downstream/navidrome to only return the content-length is the best way to go about it. Its possible that bonob should simply proxy the request to the *sonic implementation, however I've not tested how that would work against ND or gonic etc, so for now maybe this is good enough. |
|
Hi @simojenki, thanks for the review! Proxying the HEAD request downstream makes sense as a longer-term solution if we want to perfectly mirror the sonic implementations, but considering the current scope, I'll go ahead and add the unit tests for this endpoint behavior to ensure it satisfies Sonos' requirements and doesn't regress. I'll push those shortly! |
|
Is that you Claude? |
Signed-off-by: Sigmabrogz <sigmabrogz@gmail.com>
Summary
Fixes #229
Sonos devices make HEAD requests to streaming endpoints to check track availability and content length without downloading the full audio data. This is standard HTTP behavior for streaming services.
Problem
The
/stream/track/:idendpoint only handled GET requests, causing HEAD requests to return 401 errors. This was logged in the issue as:Solution
streamTrackHandlerreq.method == "GET"to conditionally stream data vs. just headersTesting
npm run build✅Checklist
Generated with Claude Code