Add support for additional backend headers#42
Open
aboullaite wants to merge 2 commits into
Open
Conversation
added 2 commits
June 30, 2026 09:51
Allow host processes to pass extra headers to backend API requests through the SAVE_TO_SPOTIFY_HEADERS environment variable. The value is a JSON array of "Key:Value" strings. Only headers prefixed with X-STS- are accepted; all others are silently dropped. Headers are parsed once at startup and applied to every backend request via doAPIRequest.
125096d to
35c96f8
Compare
|
|
||
| var entries map[string]string | ||
| if err := json.Unmarshal([]byte(raw), &entries); err != nil { | ||
| return nil |
Collaborator
There was a problem hiding this comment.
this would happen when the SAVE_TO_SPOTIFY_HEADERS var is set but contains invalid json, would be good to log when that happens
| for _, k := range keys { | ||
| key := textproto.CanonicalMIMEHeaderKey(strings.TrimSpace(k)) | ||
| val := strings.TrimSpace(in[k]) | ||
| if val == "" || !strings.HasPrefix(key, additionalHeaderPrefix) { |
Collaborator
There was a problem hiding this comment.
The X-STS-* prefix check is critical, without it a value like {"Authorization": "Bearer ..."} in SAVE_TO_SPOTIFY_HEADERS would silently overwrite the CLI's own auth header, since the transport runs after doAPIRequest sets Authorization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SAVE_TO_SPOTIFY_HEADERSenv var for host processes to inject additional headers into backend API requestsX-STS-*prefix (any casing; keys are canonicalized)Test plan
go build ./...andgo vet ./...passgo test ./...— all existing and new tests passX-STS-*headers are rejected; lowercasex-sts-*keys are accepted and canonicalized (tested)