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

Commit 3b0adaa

Browse files
author
John Luo
committed
cleanup
1 parent c3c6229 commit 3b0adaa

File tree

7 files changed

+55
-59
lines changed

7 files changed

+55
-59
lines changed

src/Kestrel.Core/Http2Limits.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
1212
public class Http2Limits
1313
{
1414
private int _maxStreamsPerConnection = 100;
15-
private int _maxFrameSize = Http2PeerSettings.MinAllowedMaxFrameSize;
15+
private int _maxFrameSize = MinAllowedMaxFrameSize;
16+
17+
// These are limits defined by the RFC https://tools.ietf.org/html/rfc7540#section-4.2
18+
public const int MinAllowedMaxFrameSize = 16 * 1024;
19+
public const int MaxAllowedMaxFrameSize = 16 * 1024 * 1024 - 1;
1620

1721
/// <summary>
1822
/// Limits the number of concurrent request streams per HTTP/2 connection. Excess streams will be refused.
@@ -44,9 +48,9 @@ public int MaxFrameSize
4448
get => _maxFrameSize;
4549
set
4650
{
47-
if (value < Http2PeerSettings.MinAllowedMaxFrameSize || value > Http2PeerSettings.MaxAllowedMaxFrameSize)
51+
if (value < MinAllowedMaxFrameSize || value > MaxAllowedMaxFrameSize)
4852
{
49-
throw new ArgumentOutOfRangeException(nameof(value), value, CoreStrings.FormatArgumentOutOfRange(Http2PeerSettings.MinAllowedMaxFrameSize, Http2PeerSettings.MaxAllowedMaxFrameSize));
53+
throw new ArgumentOutOfRangeException(nameof(value), value, CoreStrings.FormatArgumentOutOfRange(MinAllowedMaxFrameSize, MaxAllowedMaxFrameSize));
5054
}
5155
_maxFrameSize = value;
5256
}

src/Kestrel.Core/Internal/Http2/Http2Frame.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public partial class Http2Frame
2929
private readonly byte[] _data;
3030
private readonly uint _maxFrameSize;
3131

32-
// Internal for testing
33-
internal Http2Frame()
34-
: this(Http2PeerSettings.MinAllowedMaxFrameSize)
35-
{ }
36-
3732
public Http2Frame(uint maxFrameSize)
3833
{
3934
_maxFrameSize = maxFrameSize;

src/Kestrel.Core/Internal/Http2/Http2FrameWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Http2FrameWriter
2121
// Literal Header Field without Indexing - Indexed Name (Index 8 - :status)
2222
private static readonly byte[] _continueBytes = new byte[] { 0x08, 0x03, (byte)'1', (byte)'0', (byte)'0' };
2323

24-
private uint _maxFrameSize = Http2PeerSettings.MinAllowedMaxFrameSize;
24+
private uint _maxFrameSize = Http2Limits.MinAllowedMaxFrameSize;
2525
private Http2Frame _outgoingFrame;
2626
private readonly object _writeLock = new object();
2727
private readonly HPackEncoder _hpackEncoder = new HPackEncoder();

src/Kestrel.Core/Internal/Http2/Http2PeerSettings.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ public class Http2PeerSettings
1212
public const bool DefaultEnablePush = true;
1313
public const uint DefaultMaxConcurrentStreams = uint.MaxValue;
1414
public const uint DefaultInitialWindowSize = 65535;
15-
public const uint DefaultMaxFrameSize = MinAllowedMaxFrameSize;
15+
public const uint DefaultMaxFrameSize = Http2Limits.MinAllowedMaxFrameSize;
1616
public const uint DefaultMaxHeaderListSize = uint.MaxValue;
1717
public const uint MaxWindowSize = int.MaxValue;
1818

19-
public const int MinAllowedMaxFrameSize = 16 * 1024;
20-
public const int MaxAllowedMaxFrameSize = 16 * 1024 * 1024 - 1;
21-
2219
public uint HeaderTableSize { get; set; } = DefaultHeaderTableSize;
2320

2421
public bool EnablePush { get; set; } = DefaultEnablePush;
@@ -67,11 +64,11 @@ public void Update(IList<Http2PeerSetting> settings)
6764
InitialWindowSize = value;
6865
break;
6966
case Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE:
70-
if (value < MinAllowedMaxFrameSize || value > MaxAllowedMaxFrameSize)
67+
if (value < Http2Limits.MinAllowedMaxFrameSize || value > Http2Limits.MaxAllowedMaxFrameSize)
7168
{
7269
throw new Http2SettingsParameterOutOfRangeException(Http2SettingsParameter.SETTINGS_MAX_FRAME_SIZE,
73-
lowerBound: MinAllowedMaxFrameSize,
74-
upperBound: MaxAllowedMaxFrameSize);
70+
lowerBound: Http2Limits.MinAllowedMaxFrameSize,
71+
upperBound: Http2Limits.MaxAllowedMaxFrameSize);
7572
}
7673

7774
MaxFrameSize = value;

test/Kestrel.InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,28 @@ public class Http2ConnectionTests : Http2TestBase
7777
private static readonly byte[] _worldBytes = Encoding.ASCII.GetBytes("world");
7878
private static readonly byte[] _helloWorldBytes = Encoding.ASCII.GetBytes("hello, world");
7979
private static readonly byte[] _noData = new byte[0];
80-
private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2PeerSettings.MinAllowedMaxFrameSize));
80+
private static readonly byte[] _maxData = Encoding.ASCII.GetBytes(new string('a', Http2Limits.MinAllowedMaxFrameSize));
8181

8282
[Fact]
8383
public async Task Frame_Received_OverMaxSize_FrameError()
8484
{
8585
await InitializeConnectionAsync(_echoApplication);
8686

8787
await StartStreamAsync(1, _browserRequestHeaders, endStream: false);
88-
uint length = Http2PeerSettings.MinAllowedMaxFrameSize + 1;
88+
uint length = Http2Limits.MinAllowedMaxFrameSize + 1;
8989
await SendDataAsync(1, new byte[length].AsSpan(), endStream: true);
9090

9191
await WaitForConnectionErrorAsync<Http2ConnectionErrorException>(
9292
ignoreNonGoAwayFrames: true,
9393
expectedLastStreamId: 1,
9494
expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR,
95-
expectedErrorMessage: CoreStrings.FormatHttp2ErrorFrameOverLimit(length, Http2PeerSettings.MinAllowedMaxFrameSize));
95+
expectedErrorMessage: CoreStrings.FormatHttp2ErrorFrameOverLimit(length, Http2Limits.MinAllowedMaxFrameSize));
9696
}
9797

9898
[Fact]
9999
public async Task ServerSettings_ChangesRequestMaxFrameSize()
100100
{
101-
var length = Http2PeerSettings.MinAllowedMaxFrameSize + 10;
101+
var length = Http2Limits.MinAllowedMaxFrameSize + 10;
102102
_connectionContext.ServiceContext.ServerOptions.Limits.Http2.MaxFrameSize = length;
103103
_connection = new Http2Connection(_connectionContext);
104104

@@ -113,11 +113,11 @@ await ExpectAsync(Http2FrameType.HEADERS,
113113
withStreamId: 1);
114114
// The client's settings is still defaulted to Http2PeerSettings.MinAllowedMaxFrameSize so the echo response will come back in two separate frames
115115
await ExpectAsync(Http2FrameType.DATA,
116-
withLength: Http2PeerSettings.MinAllowedMaxFrameSize,
116+
withLength: Http2Limits.MinAllowedMaxFrameSize,
117117
withFlags: (byte)Http2DataFrameFlags.NONE,
118118
withStreamId: 1);
119119
await ExpectAsync(Http2FrameType.DATA,
120-
withLength: length - Http2PeerSettings.MinAllowedMaxFrameSize,
120+
withLength: length - Http2Limits.MinAllowedMaxFrameSize,
121121
withFlags: (byte)Http2DataFrameFlags.NONE,
122122
withStreamId: 1);
123123
await ExpectAsync(Http2FrameType.DATA,
@@ -2069,7 +2069,7 @@ public async Task SETTINGS_ACK_Received_DoesNotSend_ACK()
20692069
{
20702070
await InitializeConnectionAsync(_noopApplication);
20712071

2072-
var frame = new Http2Frame();
2072+
var frame = new Http2Frame(Http2Limits.MinAllowedMaxFrameSize);
20732073
frame.PrepareSettings(Http2SettingsFrameFlags.ACK);
20742074
await SendAsync(frame.Raw);
20752075

@@ -2190,7 +2190,7 @@ await WaitForConnectionErrorAsync<Http2ConnectionErrorException>(
21902190
[Fact]
21912191
public async Task SETTINGS_Received_ChangesAllowedResponseMaxFrameSize()
21922192
{
2193-
var length = Http2PeerSettings.MinAllowedMaxFrameSize + 10;
2193+
var length = Http2Limits.MinAllowedMaxFrameSize + 10;
21942194
await InitializeConnectionAsync(context =>
21952195
{
21962196
return context.Response.Body.WriteAsync(new byte[length], 0, length);

0 commit comments

Comments
 (0)