Return FormCollection.Empty when Content-Length is 0 (#1038)

* Return FormCollection.Empty when Content-Length is 0

Fixes https://github.com/aspnet/Mvc/issues/5631
This commit is contained in:
Pranav K 2018-09-13 13:35:31 -07:00 committed by GitHub
parent cbafd89960
commit d0ddb068be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -131,6 +131,11 @@ namespace Microsoft.AspNetCore.Http.Features
cancellationToken.ThrowIfCancellationRequested();
if (_request.ContentLength == 0)
{
return FormCollection.Empty;
}
if (_options.BufferBody)
{
_request.EnableRewind(_options.MemoryBufferThreshold, _options.BufferBodyLengthLimit);

View File

@ -12,6 +12,23 @@ namespace Microsoft.AspNetCore.Http.Features
{
public class FormFeatureTests
{
[Fact]
public async Task ReadFormAsync_0ContentLength_ReturnsEmptyForm()
{
var context = new DefaultHttpContext();
var responseFeature = new FakeResponseFeature();
context.Features.Set<IHttpResponseFeature>(responseFeature);
context.Request.ContentType = MultipartContentType;
context.Request.ContentLength = 0;
var formFeature = new FormFeature(context.Request, new FormOptions());
context.Features.Set<IFormFeature>(formFeature);
var formCollection = await context.Request.ReadFormAsync();
Assert.Same(FormCollection.Empty, formCollection);
}
[Theory]
[InlineData(true)]
[InlineData(false)]