Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Omit the Content-Type header for requests without bodies #3338

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

ashovlin
Copy link
Member

@ashovlin ashovlin commented Jun 8, 2024

Description

Currently if the generated marshaller doesn't set the Content-Type header for a given request AND the request uses an HTTP verb that could have a body, we set a Content-Type header here:

if (method != "GET" && method != "DELETE" && method != "HEAD")
{
if (!requestContext.Request.Headers.ContainsKey(HeaderKeys.ContentTypeHeader))
{
if (requestContext.Request.UseQueryString)
requestContext.Request.Headers[HeaderKeys.ContentTypeHeader] = "application/x-amz-json-1.0";
else
requestContext.Request.Headers[HeaderKeys.ContentTypeHeader] = AWSSDKUtils.UrlEncodedContent;
}
}

This is problematic for at least one service (Connect Outbound Campaigns) that throws 415: Unsupported Media Type when it receives a Content-Type for a POST request with no body.

Now, instead of setting Content-Type based on the verb, we set it based on if the request has a body. I think this is what we intended to do in e6f0f5e, but missed that we have this fallback logic in the core marshaller.

Motivation and Context

V1399441092

Testing

Added a new test case to our mock rest-json service to test that a POST without a body doesn't have a Content-Type header

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@ashovlin ashovlin changed the base branch from main to main-staging June 8, 2024 04:14
@ashovlin ashovlin force-pushed the shovlia/fix-content-type-no-body branch from aaf6159 to 0740385 Compare June 10, 2024 13:55
@ashovlin ashovlin force-pushed the shovlia/fix-content-type-no-body branch from 0740385 to 526b6a2 Compare June 10, 2024 13:57
@ashovlin ashovlin merged commit ffdbdd1 into main-staging Jun 12, 2024
1 check passed
@ashovlin ashovlin deleted the shovlia/fix-content-type-no-body branch June 12, 2024 13:46
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.

3 participants