Skip to content

fix(ssestream): handle content-type parameters and case in decoder lookup#291

Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/ssestream-content-type-matching
Open

fix(ssestream): handle content-type parameters and case in decoder lookup#291
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin:fix/ssestream-content-type-matching

Conversation

@MaxwellCalkin
Copy link
Copy Markdown

@MaxwellCalkin MaxwellCalkin commented Mar 8, 2026

Summary

  • NewDecoder performs an exact string match on the raw Content-Type header to find a registered decoder, but RegisterDecoder lowercases keys — creating a case-sensitivity mismatch
  • Neither function strips media type parameters (e.g., ; charset=utf-8), so a Content-Type of application/vnd.amazon.eventstream; charset=utf-8 would fail the lookup
  • When the Bedrock eventstream decoder is not matched, the binary eventstream response silently falls through to the text/event-stream SSE decoder, causing decode failures or data corruption
  • The fix uses mime.ParseMediaType (Go stdlib) to properly extract and normalize the media type before decoder lookup, consistent with how requestconfig.go already handles Content-Type parsing elsewhere in this SDK

Before:

contentType := res.Header.Get("content-type")
if t, ok := decoderTypes[contentType]; ok {  // exact match, no normalization

After:

mediaType, _, _ := mime.ParseMediaType(res.Header.Get("content-type"))
if t, ok := decoderTypes[strings.ToLower(mediaType)]; ok {  // normalized + lowercased

Test plan

  • Verify Bedrock streaming still works with standard content-type header
  • Verify decoder is correctly matched when server returns content-type with parameters (e.g., application/vnd.amazon.eventstream; charset=utf-8)
  • Verify decoder is correctly matched with mixed-case content-type headers
  • Run existing test suite to confirm no regressions

🤖 Generated with Claude Code

AI Disclosure

This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).

…okup

NewDecoder performs an exact string match on the Content-Type header to
find a registered decoder. However, RegisterDecoder lowercases the key
while NewDecoder does not lowercase the header value before lookup.
Additionally, neither handles media type parameters (e.g.,
"; charset=utf-8").

This means that if a server returns a Content-Type with different casing
(e.g., "Application/Vnd.Amazon.Eventstream") or with parameters (e.g.,
"application/vnd.amazon.eventstream; charset=utf-8"), the registered
Bedrock eventstream decoder would not be found. The response would
instead be parsed as a text/event-stream SSE, causing decode failures
or data corruption.

The fix uses mime.ParseMediaType to properly extract and normalize the
media type before looking up the decoder, consistent with how
requestconfig.go already handles content-type parsing elsewhere in the
SDK.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MaxwellCalkin MaxwellCalkin requested a review from a team as a code owner March 8, 2026 21: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