Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 421d1a1

Browse files
committed
Throw multiple content lengths
1 parent 4718d29 commit 421d1a1

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/BadHttpRequestException.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ internal static BadHttpRequestException GetException(RequestRejectionReason reas
4343
case RequestRejectionReason.MalformedRequestInvalidHeaders:
4444
ex = new BadHttpRequestException("Malformed request: invalid headers.", StatusCodes.Status400BadRequest);
4545
break;
46+
case RequestRejectionReason.MultipleContentLengths:
47+
ex = new BadHttpRequestException("Multiple content length headers.", StatusCodes.Status400BadRequest);
48+
break;
4649
case RequestRejectionReason.UnexpectedEndOfRequestContent:
4750
ex = new BadHttpRequestException("Unexpected end of request content.", StatusCodes.Status400BadRequest);
4851
break;

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.Generated.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5123,7 +5123,7 @@ private unsafe void AppendNonPrimaryHeaders(byte[] keyBytes, int keyOffset, int
51235123
{
51245124
if (ContentLength.HasValue)
51255125
{
5126-
ThrowInvalidRequestContentLengthException(AppendValue(HeaderUtilities.FormatInt64(ContentLength.Value), value).ToString());
5126+
ThrowRequestMultipleContentLengths();
51275127
}
51285128
else
51295129
{

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ protected static void ThrowInvalidRequestContentLengthException(string value)
450450
throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidContentLength, value);
451451
}
452452

453+
protected static void ThrowRequestMultipleContentLengths()
454+
{
455+
throw BadHttpRequestException.GetException(RequestRejectionReason.MultipleContentLengths);
456+
}
457+
453458
private static void ThrowInvalidHeaderCharacter(char ch)
454459
{
455460
throw new InvalidOperationException(string.Format("Invalid non-ASCII or control character in header: 0x{0:X4}", (ushort)ch));

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/RequestRejectionReason.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public enum RequestRejectionReason
1515
InvalidRequestLine,
1616
MalformedRequestInvalidHeaders,
1717
InvalidContentLength,
18+
MultipleContentLengths,
1819
UnexpectedEndOfRequestContent,
1920
BadChunkSuffix,
2021
BadChunkSizeData,

tools/Microsoft.AspNetCore.Server.Kestrel.GeneratedCode/KnownHeaders.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ static string AppendSwitch(IEnumerable<IGrouping<int, KnownHeader>> values, stri
3434
{{{(header.Identifier == "ContentLength" ? $@"
3535
if (ContentLength.HasValue)
3636
{{
37-
ThrowInvalid{(className == "FrameResponseHeaders" ? "Response" : "Request")}ContentLengthException(AppendValue(HeaderUtilities.FormatInt64(ContentLength.Value), value).ToString());
37+
ThrowRequestMultipleContentLengths();
3838
}}
3939
else
4040
{{
41-
ContentLength = Parse{(className == "FrameResponseHeaders" ? "Response" : "Request")}ContentLength(value);
41+
ContentLength = ParseRequestContentLength(value);
4242
}}
4343
return;" : $@"
4444
if ({header.TestBit()})

0 commit comments

Comments
 (0)