Skip to content

Preserve provider header overrides and apply custom_headers on Anthropic providers #3125

@chindris-mihai-alexandru

Description

Summary
Forge currently applies global HTTP defaults in a way that can override provider-specific headers, and the Anthropic provider path does not forward provider.custom_headers at all.

Why this matters
Some third-party gateways accept requests only when a provider-specific header shape is preserved. The concrete reproducer on my side was a strict third-party gateway, but the bug is generic:

  1. ForgeHttpInfra overwrites provider-specific X-Title and HTTP-Referer values with Forge defaults.
  2. Anthropic provider requests do not append provider.custom_headers.
  3. As a result, providers that require specific User-Agent / X-Title / HTTP-Referer / Origin headers cannot be integrated cleanly through provider.json alone.

Current behavior

  • Provider-level User-Agent can survive, but X-Title and HTTP-Referer are overwritten by Forge defaults.
  • Anthropic requests ignore provider.custom_headers entirely.

Expected behavior

  • Forge default headers should only be applied when the provider did not already set them.
  • Anthropic requests should honor provider.custom_headers the same way OpenAI requests do.

Suggested fix

  • In crates/forge_infra/src/http.rs:
    • preserve provider overrides for User-Agent, X-Title, and HTTP-Referer
    • still add x-app-version and Connection defaults
  • In crates/forge_repo/src/provider/anthropic.rs:
    • append provider.custom_headers to the outgoing request headers

Validation
The local patch was verified with:

  • cargo test -q -p forge_repo -p forge_infra
  • cargo check -q

And I also verified that the patch applies cleanly on upstream/main and the targeted test suite still passes after applying it.

Co-Authored-By: ForgeCode noreply@forgecode.dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions