Skip to content

Commit c20c3da

Browse files
committed
HTTP/3: Add unit test for MaxRequestLineSize limit
1 parent ec69111 commit c20c3da

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ private bool TryValidatePseudoHeaders()
701701
var requestLineLength = _methodText!.Length + Scheme!.Length + hostText.Length + path.Length;
702702
if (requestLineLength > ServerOptions.Limits.MaxRequestLineSize)
703703
{
704-
Abort(new ConnectionAbortedException(CoreStrings.BadRequest_RequestLineTooLong), Http3ErrorCode.ProtocolError);
704+
Abort(new ConnectionAbortedException(CoreStrings.BadRequest_RequestLineTooLong), Http3ErrorCode.RequestRejected);
705705
return false;
706706
}
707707

src/Servers/Kestrel/Core/src/KestrelServerLimits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public long? MaxRequestBufferSize
9191
/// Defaults to 8,192 bytes (8 KB).
9292
/// </summary>
9393
/// <remarks>
94-
/// For HTTP/2 this measures the total size of the required pseudo headers
94+
/// For HTTP/2 and HTTP/3 this measures the total size of the required pseudo headers
9595
/// :method, :scheme, :authority, and :path.
9696
/// </remarks>
9797
public int MaxRequestLineSize

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,24 @@ await ExpectAsync(Http2FrameType.HEADERS,
26122612
await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
26132613
}
26142614

2615+
[Fact]
2616+
public async Task HEADERS_Received_RequestLineLength_StreamError()
2617+
{
2618+
var headers = new[]
2619+
{
2620+
new KeyValuePair<string, string>(HeaderNames.Method, new string('A', 8192 / 2)),
2621+
new KeyValuePair<string, string>(HeaderNames.Path, "/" + new string('A', 8192 / 2)),
2622+
new KeyValuePair<string, string>(HeaderNames.Scheme, "http")
2623+
};
2624+
2625+
await InitializeConnectionAsync(_noopApplication);
2626+
await StartStreamAsync(1, headers, endStream: true);
2627+
2628+
await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, CoreStrings.BadRequest_RequestLineTooLong);
2629+
2630+
await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
2631+
}
2632+
26152633
[Fact]
26162634
public async Task PRIORITY_Received_StreamIdZero_ConnectionError()
26172635
{

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3StreamTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,5 +2358,18 @@ public async Task MaxRequestBodySize_AppCanRaiseLimit(bool includeContentLength)
23582358
Assert.Equal("200", receivedHeaders[HeaderNames.Status]);
23592359
Assert.Equal("0", receivedHeaders[HeaderNames.ContentLength]);
23602360
}
2361+
2362+
[Fact]
2363+
public Task HEADERS_Received_RequestLineLength_Error()
2364+
{
2365+
var headers = new[]
2366+
{
2367+
new KeyValuePair<string, string>(HeaderNames.Method, new string('A', 8192 / 2)),
2368+
new KeyValuePair<string, string>(HeaderNames.Path, "/" + new string('A', 8192 / 2)),
2369+
new KeyValuePair<string, string>(HeaderNames.Scheme, "http")
2370+
};
2371+
2372+
return HEADERS_Received_InvalidHeaderFields_StreamError(headers, CoreStrings.BadRequest_RequestLineTooLong, Http3ErrorCode.RequestRejected);
2373+
}
23612374
}
23622375
}

0 commit comments

Comments
 (0)