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

Commit dc8004e

Browse files
committed
Feedback
1 parent a1bfe6b commit dc8004e

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ public abstract class FrameHeaders : IHeaderDictionary
1818
protected Dictionary<string, StringValues> MaybeUnknown;
1919
protected Dictionary<string, StringValues> Unknown => MaybeUnknown ?? (MaybeUnknown = new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase));
2020

21-
public long? ContentLength {
21+
public long? ContentLength
22+
{
2223
get { return _contentLength; }
2324
set
2425
{
2526
if (value.HasValue && value.Value < 0)
2627
{
27-
ThrowInvalidResponseContentLengthException(value.Value);
28+
ThrowInvalidContentLengthException(value.Value);
2829
}
2930
_contentLength = value;
3031
}
@@ -423,26 +424,11 @@ public static unsafe TransferCoding GetFinalTransferCoding(StringValues transfer
423424
return transferEncodingOptions;
424425
}
425426

426-
protected static void ThrowInvalidResponseContentLengthException(long value)
427+
private static void ThrowInvalidContentLengthException(long value)
427428
{
428429
throw new ArgumentOutOfRangeException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number.");
429430
}
430431

431-
protected static void ThrowInvalidResponseContentLengthException(string value)
432-
{
433-
throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number.");
434-
}
435-
436-
protected static void ThrowInvalidRequestContentLengthException(string value)
437-
{
438-
throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidContentLength, value);
439-
}
440-
441-
protected static void ThrowRequestMultipleContentLengths()
442-
{
443-
throw BadHttpRequestException.GetException(RequestRejectionReason.MultipleContentLengths);
444-
}
445-
446432
private static void ThrowInvalidHeaderCharacter(char ch)
447433
{
448434
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/FrameRequestHeaders.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static long ParseContentLength(string value)
1717
long parsed;
1818
if (!HeaderUtilities.TryParseInt64(value, out parsed))
1919
{
20-
ThrowInvalidRequestContentLengthException(value);
20+
ThrowInvalidContentLengthException(value);
2121
}
2222

2323
return parsed;
@@ -46,6 +46,16 @@ private unsafe void AppendUnknownHeaders(byte* pKeyBytes, int keyLength, string
4646
Unknown[key] = AppendValue(existing, value);
4747
}
4848

49+
private static void ThrowInvalidContentLengthException(string value)
50+
{
51+
throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidContentLength, value);
52+
}
53+
54+
private static void ThrowMultipleContentLengths()
55+
{
56+
throw BadHttpRequestException.GetException(RequestRejectionReason.MultipleContentLengths);
57+
}
58+
4959
public Enumerator GetEnumerator()
5060
{
5161
return new Enumerator(this);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections;
56
using System.Collections.Generic;
67
using System.Runtime.CompilerServices;
@@ -59,7 +60,7 @@ private static long ParseContentLength(string value)
5960
long parsed;
6061
if (!HeaderUtilities.TryParseInt64(value, out parsed))
6162
{
62-
ThrowInvalidResponseContentLengthException(value);
63+
ThrowInvalidContentLengthException(value);
6364
}
6465

6566
return parsed;
@@ -72,6 +73,11 @@ private void SetValueUnknown(string key, StringValues value)
7273
Unknown[key] = value;
7374
}
7475

76+
private static void ThrowInvalidContentLengthException(string value)
77+
{
78+
throw new InvalidOperationException($"Invalid Content-Length: \"{value}\". Value must be a positive integral number.");
79+
}
80+
7581
public partial struct Enumerator : IEnumerator<KeyValuePair<string, StringValues>>
7682
{
7783
private readonly FrameResponseHeaders _collection;

0 commit comments

Comments
 (0)