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

Fixed issue "(EmptyBodyBehavior = EmptyBodyBehavior.Allow)" not being honored #1885

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

normj
Copy link
Member

@normj normj commented Nov 26, 2024

Issue #, if available:
#1854

Description of changes:
ASP.NET Core controllers that were configured with (EmptyBodyBehavior = EmptyBodyBehavior.Allow) should allow requests for PUT and POST to have no body. The controller parameter would be null in this case. This is controlled by our underlying implementation of ASP.NET Core's IHttpRequestBodyDetectionFeature interface. Our implementation check to see if the Body property was null or not. This didn't really do anything because we initialize the Body to an empty MemoryStream.

When looking at the docs for IHttpRequestBodyDetectionFeature.CanHaveBody it says it should return true for HTTP 1.1 if the request body length is greater then 0. The use case of running ASP.NET Core through Lambda only supports HTTP 1.1. So the fix for the issue is instead of just checking null for the body also check if the length is greater then 0.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@normj normj merged commit 71a9ce6 into dev Nov 26, 2024
4 checks passed
@normj normj deleted the normj/aspnetcore-emptybody branch November 26, 2024 19:29
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