fix: don't emit duplicate Content-Type when header is bound - #760
Open
Alan4506 wants to merge 1 commit into
Open
fix: don't emit duplicate Content-Type when header is bound#760Alan4506 wants to merge 1 commit into
Alan4506 wants to merge 1 commit into
Conversation
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.
Issue
Bedrock Runtime's InvokeModel and InvokeModelWithResponseStream bind their
contentTypeinput to theContent-Typeheader. Calling either operation withcontent_typeset always fails against the live service:Root cause
For blob payloads, the serializer computes a default
Content-Type(serializers.py#L108-L118). It then appends the default without checking the existing headers (serializers.py#L172-L174):At this point the
httpHeaderbinding has already written the user's value into the same list. The request goes out with two values:The duplicate header breaks the SigV4 signature check, so the service rejects the request.
HTTPResponseSerializerhas the same pattern at serializers.py#L360-L362.Fix
Apply the payload default only when no
Content-Typeheader is already bound, at both sites:Header bindings now take precedence over the protocol default. When the input does not set the bound member, the header binding writes nothing and the default applies as before.
Testing
Ran the script below against the live Bedrock Runtime service:
Before this change:
After this change:
Also added a regression test to
packages/smithy-http/tests/unit/test_serializers.py. The case fails without the fix.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.