Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Return FormCollection.Empty when Content-Length is 0 (#1038)
Browse files Browse the repository at this point in the history
* Return FormCollection.Empty when Content-Length is 0

Fixes aspnet/Mvc#5631
  • Loading branch information
pranavkm authored Sep 13, 2018
1 parent cbafd89 commit d0ddb06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Microsoft.AspNetCore.Http/Features/FormFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ private async Task<IFormCollection> InnerReadFormAsync(CancellationToken cancell

cancellationToken.ThrowIfCancellationRequested();

if (_request.ContentLength == 0)
{
return FormCollection.Empty;
}

if (_options.BufferBody)
{
_request.EnableRewind(_options.MemoryBufferThreshold, _options.BufferBodyLengthLimit);
Expand Down
17 changes: 17 additions & 0 deletions test/Microsoft.AspNetCore.Http.Tests/Features/FormFeatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit d0ddb06

Please sign in to comment.