fix(provider): preserve custom header overrides#3126
fix(provider): preserve custom header overrides#3126chindris-mihai-alexandru wants to merge 3 commits intotailcallhq:mainfrom
Conversation
Co-Authored-By: ForgeCode <noreply@forgecode.dev>
There was a problem hiding this comment.
Pull request overview
Preserves provider-specific header overrides for key OpenRouter-related headers and ensures Anthropic requests forward provider-level custom headers, addressing integration limitations described in #3125.
Changes:
- Update Forge HTTP default-header application to avoid overwriting provider-supplied
User-Agent,X-Title, andHTTP-Referer. - Forward
provider.custom_headerson the Anthropic provider path. - Add regression tests for both behaviors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/forge_infra/src/http.rs | Applies Forge default headers conditionally (only when not already present) and adds a regression test. |
| crates/forge_repo/src/provider/anthropic.rs | Appends provider.custom_headers to Anthropic request headers and adds a regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if let Some(custom_headers) = &self.provider.custom_headers { | ||
| for (key, value) in custom_headers { | ||
| headers.push((key.clone(), value.clone())); | ||
| } | ||
| } |
There was a problem hiding this comment.
Provider custom headers are appended as raw strings, but later these headers are converted via create_headers(...), which currently expects valid header names/values and will panic at runtime if a provider config contains an invalid header. To avoid a crash from user-supplied config, validate header names/values here (e.g., HeaderName::try_from / HeaderValue::from_str) and either skip invalid entries with a warning or surface a structured error instead of panicking.
There was a problem hiding this comment.
Fixed in e56cd82. I now validate provider custom header names and values before appending them on the Anthropic path, skip invalid entries with a warning, and added a regression test to cover invalid custom headers.
| "HTTP-Referer", | ||
| HeaderValue::from_static("https://forgecode.dev"), | ||
| ); | ||
| }; |
There was a problem hiding this comment.
There is an unnecessary trailing semicolon after the if !headers.contains_key("HTTP-Referer") { ... } block. It’s harmless but tends to trigger lint warnings and is inconsistent with the other if blocks in this function; remove the semicolon for consistency.
| }; | |
| } |
There was a problem hiding this comment.
Fixed in e56cd82. I removed the trailing semicolon after the HTTP-Referer override block for consistency with the surrounding conditionals.
Co-Authored-By: ForgeCode <noreply@forgecode.dev>
Summary
User-Agent,X-Title, andHTTP-Refererprovider.custom_headerson Anthropic requestsWhy
Forge currently applies global HTTP defaults in a way that can override provider-specific headers, and the Anthropic provider path ignores
provider.custom_headersentirely.That makes some provider integrations impossible to express cleanly through provider config alone.
Changes
crates/forge_infra/src/http.rsUser-Agent,X-Title, andHTTP-Refererwhen the provider did not already set themx-app-versionandConnectiondefaults unchangedcrates/forge_repo/src/provider/anthropic.rsprovider.custom_headersto Anthropic request headersVerification
cargo test -q -p forge_repo -p forge_infracargo check -qupstream/mainCloses #3125
Co-Authored-By: ForgeCode noreply@forgecode.dev