`magpie provider set <id> header.anthropic-beta=…` replaced the betas each request carried: provider.Sign wrote the user's headers over what the gateway had set, so Claude Code's own betas (claude-code-…, interleaved thinking, 1M context's context-1m-2025-08-07 for a [1m] model) and fast mode's were dropped, and a name typed in another case went out as a second anthropic-beta line beside the gateway's. anthropic-beta is now a list header (provider.ListHeader): Sign merges the user's value into the request's (provider.MergeList: the request's items first, then the user's, each once, empty ones left out, one line under the name as typed). Every other header of the user's still replaces magpie's, as before. The gateway then fits the merged list as it fits the agent's (fitUserBetas, after Sign): a beta the provider has refused (400 Unexpected value(s) `x` for the `anthropic-beta` header) is left out from the retry and from then on, the user's own as well as the agent's; one it takes is always sent. magpie adds no 1M beta of its own: Claude Code 2.1.289 itself sends context-1m-2025-08-07 for a [1m] model to any base URL (its long_context beta is asked when the model matches /\[1m\]/ and is among those kept for third-party endpoints), magpie writes 1M models into Claude Code marked [1m], and the gateway passes it on. Per-endpoint header sets were left out: one set of headers rides on every request to a key+URL provider. docs/reference.md says how header.* works and that anthropic-beta adds. TestSignMergesListHeaders (internal/provider: merged in order, deduped, the request's line not kept beside it, another header still replaced) and TestUserBetasMergeWithTheAgents (internal/gateway: a relay that refuses one of the agent's betas and one of the user's gets the agent's then the user's, both refused ones dropped on the retry and not sent again) are new and fail without the change; TestUserBetasAlone (the user's betas sent on a request with none) passes either way. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (internal/provider failed once under load in the first full run and passed in the second).
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// A provider's anthropic-beta adds to the request's, in any case, after it
|
|
// and without repeats; any other header of the user's replaces the request's.
|
|
func TestSignMergesListHeaders(t *testing.T) {
|
|
p := Provider{ID: "relay", Key: "k", Anthropic: "https://relay.example/anthropic",
|
|
Headers: map[string]string{"anthropic-beta": "b, ,a,c", "X-Thing": "mine"}}
|
|
req, _ := http.NewRequest("POST", "https://relay.example/anthropic/v1/messages", nil)
|
|
req.Header.Set("Anthropic-Beta", "a,b")
|
|
req.Header.Set("X-Thing", "theirs")
|
|
if err := p.Sign(context.Background(), req, Anthropic, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := req.Header["anthropic-beta"]; !slices.Equal(got, []string{"a,b,c"}) {
|
|
t.Fatalf("anthropic-beta = %q, want a,b,c", got)
|
|
}
|
|
if _, ok := req.Header["Anthropic-Beta"]; ok {
|
|
t.Fatalf("the request's own line was kept beside the merged one: %v", req.Header)
|
|
}
|
|
if got := req.Header["X-Thing"]; !slices.Equal(got, []string{"mine"}) {
|
|
t.Fatalf("X-Thing = %q, want the user's", got)
|
|
}
|
|
}
|