fix(ssestream): handle content-type parameters and case in decoder lookup#291
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
fix(ssestream): handle content-type parameters and case in decoder lookup#291MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NewDecoderperforms an exact string match on the rawContent-Typeheader to find a registered decoder, butRegisterDecoderlowercases keys — creating a case-sensitivity mismatch; charset=utf-8), so a Content-Type ofapplication/vnd.amazon.eventstream; charset=utf-8would fail the lookupmime.ParseMediaType(Go stdlib) to properly extract and normalize the media type before decoder lookup, consistent with howrequestconfig.goalready handles Content-Type parsing elsewhere in this SDKBefore:
After:
Test plan
application/vnd.amazon.eventstream; charset=utf-8)🤖 Generated with Claude Code
AI Disclosure
This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).