Skip to content

Commit ee61480

Browse files
committed
Feedback
1 parent 69640f8 commit ee61480

File tree

5 files changed

+57
-33
lines changed

5 files changed

+57
-33
lines changed

src/Servers/IIS/IIS/src/BadHttpRequestException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using System.Runtime.CompilerServices;
66
using Microsoft.AspNetCore.Http;
7-
using Microsoft.Extensions.Primitives;
87

98
namespace Microsoft.AspNetCore.Server.IIS
109
{
@@ -16,6 +15,7 @@ private BadHttpRequestException(string message, int statusCode, RequestRejection
1615
StatusCode = statusCode;
1716
Reason = reason;
1817
}
18+
1919
public int StatusCode { get; }
2020

2121
internal RequestRejectionReason Reason { get; }

src/Servers/IIS/IIS/src/Core/IISHttpContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,13 @@ private void InitializeRequestIO()
292292
{
293293
Debug.Assert(!HasStartedConsumingRequestBody);
294294

295-
HasStartedConsumingRequestBody = true;
296295
if (RequestHeaders.ContentLength > MaxRequestBodySize)
297296
{
298297
BadHttpRequestException.Throw(RequestRejectionReason.RequestBodyTooLarge);
299298
}
300299

300+
HasStartedConsumingRequestBody = true;
301+
301302
EnsureIOInitialized();
302303

303304
_bodyInputPipe = new Pipe(new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.ThreadPool, minimumSegmentSize: MinAllocBufferSize));

src/Servers/IIS/IIS/src/Core/IISHttpContextOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override async Task<bool> ProcessRequestAsync()
5353
{
5454
_streams.Stop();
5555

56-
if (!HasResponseStarted && _requestRejectedException == null && _applicationException == null && _onStarting != null)
56+
if (!HasResponseStarted && _applicationException == null && _onStarting != null)
5757
{
5858
await FireOnStarting();
5959
// Dispose

src/Servers/IIS/IIS/src/RequestRejectionReason.cs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,6 @@ namespace Microsoft.AspNetCore.Server.IIS
55
{
66
internal enum RequestRejectionReason
77
{
8-
UnrecognizedHTTPVersion,
9-
InvalidRequestLine,
10-
InvalidRequestHeader,
11-
InvalidRequestHeadersNoCRLF,
12-
MalformedRequestInvalidHeaders,
13-
InvalidContentLength,
14-
MultipleContentLengths,
15-
UnexpectedEndOfRequestContent,
16-
BadChunkSuffix,
17-
BadChunkSizeData,
18-
ChunkedRequestIncomplete,
19-
InvalidRequestTarget,
20-
InvalidCharactersInHeaderName,
21-
RequestLineTooLong,
22-
HeadersExceedMaxTotalSize,
23-
TooManyHeaders,
24-
RequestBodyTooLarge,
25-
RequestHeadersTimeout,
26-
RequestBodyTimeout,
27-
FinalTransferCodingNotChunked,
28-
LengthRequired,
29-
LengthRequiredHttp10,
30-
OptionsMethodRequired,
31-
ConnectMethodRequired,
32-
MissingHostHeader,
33-
MultipleHostHeaders,
34-
InvalidHostHeader,
35-
UpgradeRequestCannotHavePayload,
36-
RequestBodyExceedsContentLength
8+
RequestBodyTooLarge
379
}
3810
}

src/Servers/IIS/IIS/test/IIS.Tests/MaxRequestBodySizeTests.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,57 @@ await connection.Send(
142142
}
143143
}
144144

145+
[ConditionalFact]
146+
public async Task DoesNotRejectBodylessPostWithZeroContentLengthRequestWithZeroMaxRequestBodySize()
147+
{
148+
using (var testServer = await TestServer.Create(
149+
async ctx =>
150+
{
151+
await ctx.Request.Body.ReadAsync(new byte[2000]);
152+
153+
}, LoggerFactory, new IISServerOptions { MaxRequestBodySize = 0 }))
154+
{
155+
using (var connection = testServer.CreateConnection())
156+
{
157+
await connection.Send(
158+
"POST / HTTP/1.1",
159+
$"Content-Length: 0",
160+
"Host: localhost",
161+
"",
162+
"");
163+
164+
await connection.Receive("HTTP/1.1 200 OK");
165+
}
166+
}
167+
}
168+
169+
[ConditionalFact]
170+
public async Task DoesNotRejectBodylessPostWithEmptyChunksRequestWithZeroMaxRequestBodySize()
171+
{
172+
using (var testServer = await TestServer.Create(
173+
async ctx =>
174+
{
175+
await ctx.Request.Body.ReadAsync(new byte[2000]);
176+
177+
}, LoggerFactory, new IISServerOptions { MaxRequestBodySize = 0 }))
178+
{
179+
using (var connection = testServer.CreateConnection())
180+
{
181+
await connection.Send(
182+
"POST / HTTP/1.1",
183+
$"Transfer-Encoding: chunked",
184+
"Host: localhost",
185+
"",
186+
"0",
187+
"",
188+
"");
189+
190+
await connection.Receive("HTTP/1.1 200 OK");
191+
}
192+
}
193+
}
194+
195+
145196
[ConditionalFact]
146197
public async Task SettingMaxRequestBodySizeAfterReadingFromRequestBodyThrows()
147198
{
@@ -240,7 +291,7 @@ public async Task EveryReadFailsWhenContentLengthHeaderExceedsGlobalLimit()
240291
{
241292
await connection.Send(
242293
"POST / HTTP/1.1",
243-
"Host:",
294+
"Host: localhost",
244295
"Content-Length: " + (new IISServerOptions().MaxRequestBodySize + 1),
245296
"",
246297
"");

0 commit comments

Comments
 (0)