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

Commit 74570f3

Browse files
committed
Use null instead of -1 to make buffer size unlimited
1 parent fd30294 commit 74570f3

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public Connection(ListenerContext context, UvStreamHandle socket) : base(context
4949

5050
ConnectionId = GenerateConnectionId(Interlocked.Increment(ref _lastConnectionId));
5151

52-
if (ServerOptions.MaxInputBufferLength == -1)
52+
if (ServerOptions.MaxInputBufferLength.HasValue)
5353
{
54-
_rawSocketInput = new SocketInput(Memory, ThreadPool);
54+
_rawSocketInput = new SocketInput(Memory, ThreadPool, ServerOptions.MaxInputBufferLength.Value, this, Thread);
5555
}
5656
else
5757
{
58-
_rawSocketInput = new SocketInput(Memory, ThreadPool, ServerOptions.MaxInputBufferLength, this, Thread);
58+
_rawSocketInput = new SocketInput(Memory, ThreadPool);
5959
}
6060

6161
_rawSocketOutput = new SocketOutput(Thread, _socket, Memory, this, ConnectionId, Log, ThreadPool, WriteReqPool);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ public class KestrelServerOptions
1717

1818
public IConnectionFilter ConnectionFilter { get; set; }
1919

20-
private int _maxInputBufferLength = 1024 * 1024;
21-
public int MaxInputBufferLength
20+
private int? _maxInputBufferLength = 1024 * 1024;
21+
public int? MaxInputBufferLength
2222
{
2323
get
2424
{
2525
return _maxInputBufferLength;
2626
}
2727
set
2828
{
29-
if (value < -1 || value == 0)
29+
if (value.HasValue && value.Value <= 0)
3030
{
31-
throw new ArgumentOutOfRangeException("value", "Value must be positive or -1.");
31+
throw new ArgumentOutOfRangeException("value", "Value must be null or a positive integer.");
3232
}
3333
_maxInputBufferLength = value;
3434
}

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxInputBufferLengthTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class MaxInputBufferLengthTests
2424
[InlineData(10 * 1024 * 1024, false, false)]
2525
[InlineData(Int32.MaxValue, true, false)]
2626
[InlineData(Int32.MaxValue, false, false)]
27-
[InlineData(-1, true, false)]
28-
[InlineData(-1, false, false)]
29-
public async Task LargeUpload(int maxInputBufferLength, bool sendContentLengthHeader, bool expectPause)
27+
[InlineData(null, true, false)]
28+
[InlineData(null, false, false)]
29+
public async Task LargeUpload(int? maxInputBufferLength, bool sendContentLengthHeader, bool expectPause)
3030
{
3131
// Parameters
3232
var data = new byte[10 * 1024 * 1024];
@@ -76,7 +76,7 @@ public async Task LargeUpload(int maxInputBufferLength, bool sendContentLengthHe
7676
// and server, which allow the client to send more than maxInputBufferLength before getting
7777
// paused. We assume the combined buffers are smaller than the difference between
7878
// data.Length and maxInputBufferLength.
79-
Assert.InRange(bytesWritten, maxInputBufferLength - maxSendSize + 1, data.Length - 1);
79+
Assert.InRange(bytesWritten, maxInputBufferLength.Value - maxSendSize + 1, data.Length - 1);
8080

8181
// Tell server to start reading request body
8282
startReadingRequestBody.Set();
@@ -100,7 +100,7 @@ public async Task LargeUpload(int maxInputBufferLength, bool sendContentLengthHe
100100
}
101101
}
102102

103-
private static IWebHost StartWebHost(int maxInputBufferLength, byte[] expectedBody, ManualResetEvent startReadingRequestBody,
103+
private static IWebHost StartWebHost(int? maxInputBufferLength, byte[] expectedBody, ManualResetEvent startReadingRequestBody,
104104
ManualResetEvent clientFinishedSendingRequestBody)
105105
{
106106
var host = new WebHostBuilder()

test/Microsoft.AspNetCore.Server.KestrelTests/KestrelServerOptionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void MaxInputBufferLengthDefault()
1818
}
1919

2020
[Theory]
21-
[InlineData(-2)]
21+
[InlineData(-1)]
2222
[InlineData(0)]
2323
public void MaxInputBufferInvalid(int value)
2424
{
@@ -29,9 +29,9 @@ public void MaxInputBufferInvalid(int value)
2929
}
3030

3131
[Theory]
32-
[InlineData(-1)]
32+
[InlineData(null)]
3333
[InlineData(1)]
34-
public void MaxInputBufferValid(int value)
34+
public void MaxInputBufferValid(int? value)
3535
{
3636
var o = new KestrelServerOptions();
3737
o.MaxInputBufferLength = value;

0 commit comments

Comments
 (0)