Skip to content

Commit 79a1338

Browse files
committed
Update
1 parent 99955f1 commit 79a1338

File tree

9 files changed

+59
-11
lines changed

9 files changed

+59
-11
lines changed

src/Servers/Kestrel/Core/src/Http3Limits.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
1010
/// </summary>
1111
public class Http3Limits
1212
{
13-
internal const int DefaultMaxRequestHeaderFieldSize = 8192;
13+
internal const int DefaultMaxRequestHeaderFieldSize = 16 * 1024;
1414

1515
private int _headerTableSize;
1616
private int _maxRequestHeaderFieldSize = DefaultMaxRequestHeaderFieldSize;
@@ -39,7 +39,7 @@ internal int HeaderTableSize
3939
/// <summary>
4040
/// Indicates the size of the maximum allowed size of a request header field sequence. This limit applies to both name and value sequences in their compressed and uncompressed representations.
4141
/// <para>
42-
/// Value must be greater than 0, defaults to 8192.
42+
/// Value must be greater than 0, defaults to 2^14 (16,384).
4343
/// </para>
4444
/// </summary>
4545
public int MaxRequestHeaderFieldSize

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ internal static int WriteHeader(Http3RawFrame frame, PipeWriter output)
265265
return totalLength;
266266
}
267267

268-
public ValueTask<FlushResult> WriteResponseTrailers(HttpResponseTrailers headers)
268+
public ValueTask<FlushResult> WriteResponseTrailersAsync(long streamId, HttpResponseTrailers headers)
269269
{
270270
lock (_writeLock)
271271
{
@@ -283,7 +283,7 @@ public ValueTask<FlushResult> WriteResponseTrailers(HttpResponseTrailers headers
283283
}
284284
catch (QPackEncodingException ex)
285285
{
286-
//_log.HPackEncodingError(_connectionId, streamId, hex);
286+
_log.QPackEncodingError(_connectionId, streamId, ex);
287287
_http3Stream.Abort(new ConnectionAbortedException(ex.Message, ex), Http3ErrorCode.InternalError);
288288
}
289289

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private async ValueTask<FlushResult> ProcessDataWrites()
352352
}
353353

354354
_stream.ResponseTrailers.SetReadOnly();
355-
flushResult = await _frameWriter.WriteResponseTrailers(_stream.ResponseTrailers);
355+
flushResult = await _frameWriter.WriteResponseTrailersAsync(_stream.StreamId, _stream.ResponseTrailers);
356356
}
357357
else if (readResult.IsCompleted)
358358
{

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,16 @@ private async Task ProcessHeadersFrameAsync<TContext>(IHttpApplication<TContext>
487487
_requestHeaderParsingState = RequestHeaderParsingState.Trailers;
488488
}
489489

490-
QPackDecoder.Decode(payload, handler: this);
491-
QPackDecoder.Reset();
490+
try
491+
{
492+
QPackDecoder.Decode(payload, handler: this);
493+
QPackDecoder.Reset();
494+
}
495+
catch (QPackDecodingException ex)
496+
{
497+
Log.QPackDecodingError(ConnectionId, StreamId, ex);
498+
throw new Http3StreamErrorException(ex.Message, Http3ErrorCode.InternalError);
499+
}
492500

493501
switch (_requestHeaderParsingState)
494502
{

src/Servers/Kestrel/Core/src/Internal/Infrastructure/IKestrelTrace.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Net.Http;
66
using System.Net.Http.HPack;
7+
using System.Net.Http.QPack;
78
using Microsoft.AspNetCore.Connections;
89
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
910
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3;
@@ -92,5 +93,9 @@ internal interface IKestrelTrace : ILogger
9293
void Http3FrameReceived(string connectionId, long streamId, Http3RawFrame frame);
9394

9495
void Http3FrameSending(string connectionId, long streamId, Http3RawFrame frame);
96+
97+
void QPackDecodingError(string connectionId, long streamId, QPackDecodingException ex);
98+
99+
void QPackEncodingError(string connectionId, long streamId, QPackEncodingException ex);
95100
}
96101
}

src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelTrace.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Net.Http;
66
using System.Net.Http.HPack;
7+
using System.Net.Http.QPack;
78
using Microsoft.AspNetCore.Connections;
89
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
910
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3;
@@ -151,6 +152,14 @@ internal class KestrelTrace : IKestrelTrace
151152
@"Connection id ""{ConnectionId}"" sending {type} frame for stream ID {id} with length {length}.",
152153
skipEnabledCheck: true);
153154

155+
private static readonly Action<ILogger, string, long, Exception> _qpackDecodingError =
156+
LoggerMessage.Define<string, long>(LogLevel.Debug, new EventId(48, "QPackDecodingError"),
157+
@"Connection id ""{ConnectionId}"": QPACK decoding error while decoding headers for stream ID {StreamId}.");
158+
159+
private static readonly Action<ILogger, string, long, Exception> _qpackEncodingError =
160+
LoggerMessage.Define<string, long>(LogLevel.Information, new EventId(49, "QPackEncodingError"),
161+
@"Connection id ""{ConnectionId}"": QPACK encoding error while encoding headers for stream ID {StreamId}.");
162+
154163
protected readonly ILogger _generalLogger;
155164
protected readonly ILogger _badRequestsLogger;
156165
protected readonly ILogger _connectionsLogger;
@@ -382,6 +391,16 @@ public void Http3FrameSending(string connectionId, long streamId, Http3RawFrame
382391
}
383392
}
384393

394+
public virtual void QPackDecodingError(string connectionId, long streamId, QPackDecodingException ex)
395+
{
396+
_qpackDecodingError(_http3Logger, connectionId, streamId, ex);
397+
}
398+
399+
public virtual void QPackEncodingError(string connectionId, long streamId, QPackEncodingException ex)
400+
{
401+
_qpackEncodingError(_http3Logger, connectionId, streamId, ex);
402+
}
403+
385404
public virtual void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
386405
=> _generalLogger.Log(logLevel, eventId, state, exception, formatter);
387406

src/Servers/Kestrel/perf/Microbenchmarks/Mocks/MockTrace.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Net.Http;
66
using System.Net.Http.HPack;
7+
using System.Net.Http.QPack;
78
using Microsoft.AspNetCore.Connections;
89
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
910
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
@@ -66,5 +67,7 @@ public void Http3ConnectionClosed(string connectionId, long highestOpenedStreamI
6667
public void Http3StreamAbort(string traceIdentifier, Http3ErrorCode error, ConnectionAbortedException abortReason) { }
6768
public void Http3FrameReceived(string connectionId, long streamId, Http3RawFrame frame) { }
6869
public void Http3FrameSending(string connectionId, long streamId, Http3RawFrame frame) { }
70+
public void QPackDecodingError(string connectionId, long streamId, QPackDecodingException ex) { }
71+
public void QPackEncodingError(string connectionId, long streamId, QPackEncodingException ex) { }
6972
}
7073
}

src/Servers/Kestrel/shared/test/CompositeKestrelTrace.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Net.Http;
66
using System.Net.Http.HPack;
7+
using System.Net.Http.QPack;
78
using Microsoft.AspNetCore.Connections;
89
using Microsoft.AspNetCore.Server.Kestrel.Core;
910
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
@@ -280,5 +281,17 @@ public void Http3FrameSending(string connectionId, long streamId, Http3RawFrame
280281
_trace1.Http3FrameSending(connectionId, streamId, frame);
281282
_trace2.Http3FrameSending(connectionId, streamId, frame);
282283
}
284+
285+
public void QPackDecodingError(string connectionId, long streamId, QPackDecodingException ex)
286+
{
287+
_trace1.QPackDecodingError(connectionId, streamId, ex);
288+
_trace2.QPackDecodingError(connectionId, streamId, ex);
289+
}
290+
291+
public void QPackEncodingError(string connectionId, long streamId, QPackEncodingException ex)
292+
{
293+
_trace1.QPackEncodingError(connectionId, streamId, ex);
294+
_trace2.QPackEncodingError(connectionId, streamId, ex);
295+
}
283296
}
284297
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ public async Task RequestHeadersMaxRequestHeaderFieldSize_EndsStream()
111111
new KeyValuePair<string, string>(HeaderNames.Path, "/"),
112112
new KeyValuePair<string, string>(HeaderNames.Scheme, "http"),
113113
new KeyValuePair<string, string>(HeaderNames.Authority, "localhost:80"),
114-
new KeyValuePair<string, string>("test", new string('a', 10000))
114+
new KeyValuePair<string, string>("test", new string('a', 20000))
115115
};
116116

117117
var requestStream = await InitializeConnectionAndStreamsAsync(_echoApplication);
118118

119119
await requestStream.SendHeadersAsync(headers);
120-
await requestStream.SendDataAsync(Encoding.ASCII.GetBytes("Hello world"));
121120

122-
// TODO figure out how to test errors for request streams that would be set on the Quic Stream.
123-
await requestStream.ExpectReceiveEndOfStream();
121+
await requestStream.WaitForStreamErrorAsync(
122+
Http3ErrorCode.InternalError,
123+
"The HTTP headers length exceeded the set limit of 16384 bytes.");
124124
}
125125

126126
[Fact]

0 commit comments

Comments
 (0)