aws / aws/aws-lambda-dotnet

Lambda ASP NET Core Server is returning Content-Type Header even on NoContent Response

Open
#1,123 4 comments 1 reaction 0 assignees View on GitHub
bug module/aspnetcore-support p2 queued
Dominant language
C#
Stars
1.7k
Forks
503
Avg merge
1d 5h
Merged PRs (30d)
18

Description

## Description
We are using Amazon.Lambda.AspNetCoreServer 6.0.3 and normal ASP Net Controllers and responses.
The ActionResults for NoContent (HTTP 204) and Ok (HTTP 200) are correctly returning HTTP responses with a body and without a content-type header.
The ApiGatewayProxyFunction transforms that result into the following:
{
"statusCode": 204,
"headers": {},
"multiValueHeaders": {
"Content-Type": [
null
]
},
"body": "",
"isBase64Encoded": false
}

There is two Problems with this reponse:
1. Content-Type can never be a multiValueHeader. The RFC (https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2) states that.
2. On 204 there should not even be a content-type header (and on 200 with an empty body, probably as well) See the [RFC 7231 section 3.1.5.5](https://www.rfc-editor.org/rfc/rfc7231#section-3.1.1.5) for that.

## Reproduction Steps
Implement a simple GET Endpoint that returns either NoContent() or Ok() and call it e.g. via the AWS console and the Test Lambda Template for "apigateway-aws-proxy".
The response should be similar to the one above.

### Environment

* Build Version: Amazon.Lambda.AspNetCoreServer 6.0.3
* OS Info: Lambda Image public.ecr.aws/lambda/dotnet:6-x86_64
* Build Environment: dotnet lambda toolchain (so SAM Templates)
* Targeted .NET Platform: .NET 6.0

## Resolution
- [ ] :wave: I can/would-like-to implement a fix for this problem myself

The error should be in APIGatewayProxyFunction.MarshallResponse lines 202 and following.
Content-Type will need to be written to the Headers collection, but only if there is actually content in the response.

---

This is a :bug: bug-report

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.