[GH-ISSUE #884] Fallback when using web proxy #439

Closed
opened 2026-02-27 19:30:38 +03:00 by kerem · 7 comments
Owner

Originally created by @MightyMrMuesli on GitHub (Nov 20, 2021).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/884

Originally assigned to: @roderickvd on GitHub.

When librespot is configured with --proxy it instantly falls back to "ap.spotify.com:443". http://apresolve.spotify.com/ returns 400. Strangely the proxy logs consistently list the call to http://apresolve.spotify.com/ a few milliseconds later than to ap.spotify.com:443.

Here's my configuration (using librespot dev build e064f27:

librespot.conf

--name Test
--username user
--password pass
--backend pipe
--device /var/lib/spotify
--ap-port 443
--proxy http://proxy:3128

librespot log

librespot] librespot 0.3.1 e064f27 (Built on 2021-11-20, Build ID: sPNYe7OB, Profile: release)
librespot_core::apresolve] Failed to resolve Access Point: expected value at line 1 column 1
librespot_core::apresolve] Using fallback "ap.spotify.com:443"
librespot_core::session] Connecting to AP "ap.spotify.com:443"
librespot_core::connection] Using proxy "http://proxy:3128/"
librespot_core::session] Authenticated as "user" !
librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0)
librespot_playback::convert] Converting with ditherer: tpdf
librespot_playback::audio_backend::pipe] Using pipe sink with format: S16
librespot_core::session] Country: "DE"

squid log after three restarts of librespot

# TIME                  SOURCE            REQ URL                       METHOD  RETURN DESTINATION
2021-11-20T09:30:18:330 librespot_machine ap.spotify.com:443            CONNECT 200    ap.spotify.com
2021-11-20T09:31:04:882 librespot_machine http://apresolve.spotify.com/ GET     400    apresolve.spotify.com
2021-11-20T09:31:55:575 librespot_machine ap.spotify.com:443            CONNECT 200    ap.spotify.com
2021-11-20T09:31:55:605 librespot_machine http://apresolve.spotify.com/ GET     400    apresolve.spotify.com
2021-11-20T09:47:43:952 librespot_machine ap.spotify.com:443            CONNECT 200    ap.spotify.com
2021-11-20T09:47:44:23  librespot_machine http://apresolve.spotify.com/ GET     400    apresolve.spotify.com
Originally created by @MightyMrMuesli on GitHub (Nov 20, 2021). Original GitHub issue: https://github.com/librespot-org/librespot/issues/884 Originally assigned to: @roderickvd on GitHub. When librespot is configured with --proxy it instantly falls back to "ap.spotify.com:443". http://apresolve.spotify.com/ returns 400. Strangely the proxy logs consistently list the call to http://apresolve.spotify.com/ a few milliseconds later than to ap.spotify.com:443. Here's my configuration (using librespot dev build [e064f27](https://github.com/librespot-org/librespot/commit/e064f27c13d1a7277e196b31d7f09c9fb10a5f26): librespot.conf --name Test --username user --password pass --backend pipe --device /var/lib/spotify --ap-port 443 --proxy http://proxy:3128 librespot log librespot] librespot 0.3.1 e064f27 (Built on 2021-11-20, Build ID: sPNYe7OB, Profile: release) librespot_core::apresolve] Failed to resolve Access Point: expected value at line 1 column 1 librespot_core::apresolve] Using fallback "ap.spotify.com:443" librespot_core::session] Connecting to AP "ap.spotify.com:443" librespot_core::connection] Using proxy "http://proxy:3128/" librespot_core::session] Authenticated as "user" ! librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0) librespot_playback::convert] Converting with ditherer: tpdf librespot_playback::audio_backend::pipe] Using pipe sink with format: S16 librespot_core::session] Country: "DE" squid log after three restarts of librespot # TIME SOURCE REQ URL METHOD RETURN DESTINATION 2021-11-20T09:30:18:330 librespot_machine ap.spotify.com:443 CONNECT 200 ap.spotify.com 2021-11-20T09:31:04:882 librespot_machine http://apresolve.spotify.com/ GET 400 apresolve.spotify.com 2021-11-20T09:31:55:575 librespot_machine ap.spotify.com:443 CONNECT 200 ap.spotify.com 2021-11-20T09:31:55:605 librespot_machine http://apresolve.spotify.com/ GET 400 apresolve.spotify.com 2021-11-20T09:47:43:952 librespot_machine ap.spotify.com:443 CONNECT 200 ap.spotify.com 2021-11-20T09:47:44:23 librespot_machine http://apresolve.spotify.com/ GET 400 apresolve.spotify.com
kerem 2026-02-27 19:30:38 +03:00
Author
Owner

@roderickvd commented on GitHub (Nov 20, 2021):

Could you try compiling from the new-api branch? I rewrote the access point resolver there.

<!-- gh-comment-id:974696068 --> @roderickvd commented on GitHub (Nov 20, 2021): Could you try compiling from the `new-api` branch? I rewrote the access point resolver there.
Author
Owner

@MightyMrMuesli commented on GitHub (Nov 21, 2021):

No dice. Here's the librespot log:

librespot] librespot 0.2.0 7a730f3 (Built on 2021-11-21, Build ID: Kbn4TfYZ)
librespot_core::apresolve] Failed to resolve access points, using fallbacks: expected value at line 1 column 1
librespot_core::session] Connecting to AP "ap.spotify.com:443"
librespot_core::socket] Using proxy "http://proxy:3128/"
librespot_core::session] Authenticated as "user" !
librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0)
librespot_playback::convert] Converting with ditherer: tpdf
librespot_playback::audio_backend::pipe] Using pipe sink with format: S16
librespot_core::session] Country: "DE"

The call to apresolve.spotify.com is now a specific URL in squid's access.log

2021-11-21T12:35:48:142 librespot_machine ap.spotify.com:443 CONNECT 200 ap.spotify.com
2021-11-21T12:35:48:207 librespot_machine http://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient GET 400 apresolve.spotify.com

Btw, in case it wasn't clear: Playback works fine with the fallback. I've firewalled the librespot machine so it can only communicate via proxy, no problems so far.

<!-- gh-comment-id:974800619 --> @MightyMrMuesli commented on GitHub (Nov 21, 2021): No dice. Here's the librespot log: librespot] librespot 0.2.0 7a730f3 (Built on 2021-11-21, Build ID: Kbn4TfYZ) librespot_core::apresolve] Failed to resolve access points, using fallbacks: expected value at line 1 column 1 librespot_core::session] Connecting to AP "ap.spotify.com:443" librespot_core::socket] Using proxy "http://proxy:3128/" librespot_core::session] Authenticated as "user" ! librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0) librespot_playback::convert] Converting with ditherer: tpdf librespot_playback::audio_backend::pipe] Using pipe sink with format: S16 librespot_core::session] Country: "DE" The call to apresolve.spotify.com is now a specific URL in squid's access.log 2021-11-21T12:35:48:142 librespot_machine ap.spotify.com:443 CONNECT 200 ap.spotify.com 2021-11-21T12:35:48:207 librespot_machine http://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient GET 400 apresolve.spotify.com Btw, in case it wasn't clear: Playback works fine with the fallback. I've firewalled the librespot machine so it can only communicate via proxy, no problems so far.
Author
Owner

@roderickvd commented on GitHub (Nov 21, 2021):

I don't run a proxy and don't intend to, so this is a bit hard for me to debug.

What stands out is that http://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient returns a 400 on Squid when it obviously shouldn't. Just try to open it in your web browser --when you do so via a proxy, can you confirm it loads fine? In that case can you also show the Squid log for comparison?

Another thing I notice is the difference in format between CONNECT ap.spotify.com:443 and GET http://apresolve.spotify.com/, the former specifies a port and the latter doesn't, but specifies a protocol.

Hope this helps you to diagnose a bit further.

<!-- gh-comment-id:974802519 --> @roderickvd commented on GitHub (Nov 21, 2021): I don't run a proxy and don't intend to, so this is a bit hard for me to debug. What stands out is that `http://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient` returns a 400 on Squid when it obviously shouldn't. Just try to open it in your web browser --when you do so via a proxy, can you confirm it loads fine? In that case can you also show the Squid log for comparison? Another thing I notice is the difference in format between `CONNECT ap.spotify.com:443` and `GET http://apresolve.spotify.com/`, the former specifies a port and the latter doesn't, but specifies a protocol. Hope this helps you to diagnose a bit further.
Author
Owner

@MightyMrMuesli commented on GitHub (Nov 21, 2021):

Yeah, now I feel stupid for not trying that one before...

apresolve.spotify.com doesn't accept connections with "X-Forwarded-For" in the header. My original squid configuration had "forwarded_for off" configured, which will set X-Forwarded-For to "unknown". In that case apresolve answers with "Invalid IP address provided".

I've changed the config to "forwarded_for delete" which removes the header completely and now it works:

2021-11-21T13:05:31:667 librespot_machine http://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient GET 200 apresolve.spotify.com

The same with dev:

2021-11-21T13:08:26:519 librespot_machine http://apresolve.spotify.com/ GET 200 apresolve.spotify.com

If you want to I could add a wiki page with my working squid config.

<!-- gh-comment-id:974806782 --> @MightyMrMuesli commented on GitHub (Nov 21, 2021): Yeah, now I feel stupid for not trying that one before... apresolve.spotify.com doesn't accept connections with "X-Forwarded-For" in the header. My original squid configuration had "forwarded_for off" configured, which will set X-Forwarded-For to "unknown". In that case apresolve answers with "Invalid IP address provided". I've changed the config to "forwarded_for delete" which removes the header completely and now it works: 2021-11-21T13:05:31:667 librespot_machine http://apresolve.spotify.com/?type=accesspoint&type=dealer&type=spclient GET 200 apresolve.spotify.com The same with dev: 2021-11-21T13:08:26:519 librespot_machine http://apresolve.spotify.com/ GET 200 apresolve.spotify.com If you want to I could add a wiki page with my working squid config.
Author
Owner

@roderickvd commented on GitHub (Nov 21, 2021):

apresolve.spotify.com doesn't accept connections with "X-Forwarded-For" in the header.

Are you sure? Not even with forwarded_for on?

If you want to I could add a wiki page with my working squid config.

👍

<!-- gh-comment-id:974845589 --> @roderickvd commented on GitHub (Nov 21, 2021): > apresolve.spotify.com doesn't accept connections with "X-Forwarded-For" in the header. Are you sure? Not even with `forwarded_for on`? > If you want to I could add a wiki page with my working squid config. :+1:
Author
Owner

@MightyMrMuesli commented on GitHub (Nov 21, 2021):

I tested it with forwarded_for on and indeed it works. That kind of defeats the purpose of an intermediary proxy server though, so I would prefer removing the header completely.

Added Behind web proxy with some more details in the wiki.

Thanks for helping me out!

<!-- gh-comment-id:974893660 --> @MightyMrMuesli commented on GitHub (Nov 21, 2021): I tested it with `forwarded_for on` and indeed it works. That kind of defeats the purpose of an intermediary proxy server though, so I would prefer removing the header completely. Added [Behind web proxy](https://github.com/librespot-org/librespot/wiki/Behind-web-proxy) with some more details in the wiki. Thanks for helping me out!
Author
Owner

@roderickvd commented on GitHub (Nov 22, 2021):

Thanks for that wiki addition, great stuff.

<!-- gh-comment-id:975181696 --> @roderickvd commented on GitHub (Nov 22, 2021): Thanks for that wiki addition, great stuff.
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/librespot#439
No description provided.