Skip to content

Handle missing Connection header in Bedrock signing#1706

Open
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:fix/bedrock-connection-header
Open

Handle missing Connection header in Bedrock signing#1706
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:fix/bedrock-connection-header

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jun 25, 2026

Copy link
Copy Markdown

Problem

Bedrock signing fails before the HTTP request in some cases with:
KeyError: 'connection'

The code in src/anthropic/lib/bedrock/_auth.py removes the header with del headers["connection"]. If Connection is absent (which can happen in normal httpx default header sets), httpx.Headers.__delitem__ raises before any request is sent.

Fix

  • Replace direct deletion with a case-insensitive filter of headers before signing.
  • Use a new header map that omits only Connection if present:
    new_headers = {k: v for k, v in dict(headers).items() if k.lower() != "connection"}
  • Pass new_headers into AWSRequest.

This mirrors the existing guard pattern used by the AWS auth path in this repo and preserves the intent of excluding Connection from signed headers without crashing on missing keys.

Scope & Behavior

  • No functional behavior change when a Connection header exists.
  • Safe no-op when Connection is absent.
  • Prevents signing-time failures for Bedrock requests.

File Changed

  • src/anthropic/lib/bedrock/_auth.py

Testing

Not run (per request).

@fallintoplace fallintoplace requested a review from a team as a code owner June 25, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant