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:
parent
cbafd89960
commit
d0ddb068be
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue