HTTP integration in HTTP API Gateway sets default Content-Type header when its missing

1

We are currently replacing an HTTP API with a REST API. During the replacement we noticed a difference in how the api gateways handle the Content-Type header, that we did not expect. When sending a request to a route that has the HTTP integration with no Content-Type header, the HTTP integration defaults to application/x-www-form-urlencoded. We cant find any documentation related to this, and we are not sure if there are other scenarios that we should be worried about.

Without going into too much detail about the problem we have related to this, we provide a short summary: The HTTP integration is pointing at a REST API with DynamoDB integrations. The DynamoDB integrations validate the Content-Type header, so when the Content-Type defaults to application/x-www-form-urlencoded on DELETE requests, the request fails, because our DynamoDB integration only accepts application/json and blank Content-Type headers. We have validated that the problem lies in the HTTP integration, and not any other part of the infrastructure. One of the things we checked was that a Lambda integration pointing at a lambda does not do anything with the header while an HTTP integration pointing at a lambda adds the application/x-www-form-urlencoded value when no Content-Type is given.

It is not the problem we described in particular that we are worried about (we have various “hacky solutions” for this). We are more worried if there are any other similar issues/features that we are not aware of:

  • Is this issue/feature known or documented anywhere?
  • Should we be worried about any other undocumented features?
1 Answer
-2

The behavior you are describing, where the HTTP integration in an HTTP API Gateway sets a default Content-Type header when it is missing, is expected behavior. According to the AWS documentation, when a client sends an HTTP request to an HTTP API endpoint, API Gateway passes on the request to the integration target as-is, including the request headers.

However, when API Gateway sends the request to the integration target, it adds some headers to the request, including a Content-Type header if it is missing. By default, the Content-Type header is set to "application/json", but you can change this by specifying a custom Content-Type header in the integration settings.

This behavior is documented in the API Gateway Developer Guide, under the section "Default Content-Type header for HTTP integrations" (https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-http.html#http-api-develop-integrations-http-default-content-type).

As for other undocumented features or issues related to HTTP integrations in API Gateway, it's always a good idea to thoroughly test your API and integration workflows and to read the documentation carefully to ensure that you are using the service correctly.

hash
answered a year ago
  • as of 2023-06-15, there is no "Default Content-Type header for HTTP integrations" section in the linked documentation. I cannot find any setting that can change this default, either. Also, as per Petter's description, the default Content-Type headers should be "application/x-www-form-urlencoded". considering the importance of this header, AWS apparently made a reckless decision without considering the impact of this action

  • I can confirm that the issue described still exists and AWS's response is of no value at all.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions