Skip to content

Commit 477666a

Browse files
authored
Add some comments to various internal HTTP/2 types (#57151)
* Add type comment for Http2Frame * Add type comment for Http2FrameReader * Add type comment for Http2PeerSettings * Add type comment for FlowControl * Add type comment for InputFlowControl * Add type comment for StreamInputFlowControl * Add type comment for HttpConnection * Add type comments for some HTTP/2 stream types * Add type comment for Http2FrameWriter * Add type comment for Http2KeepAlive * Add type comment for Http2Connection * Add type comment for Http2MessageBody * Add partial comments for output producer types * Use <para> tags * Use one space after a period * Add additional notes to Http2Connection
1 parent 19a66f1 commit 477666a

17 files changed

+159
-12
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
2323

2424
using BadHttpRequestException = Microsoft.AspNetCore.Http.BadHttpRequestException;
2525

26+
/// <remarks>
27+
/// Request processing code (especially <see cref="ProcessRequestsAsync"/>) shared across HTTP protocols
28+
/// via inheritance.
29+
/// <para/>
30+
/// HTTP/1.1 uses it at the connection level and resets it between requests.
31+
/// HTTP/2 and HTTP/3 use it at the stream level.
32+
/// </remarks>
2633
internal abstract partial class HttpProtocol : IHttpResponseControl
2734
{
2835
private static readonly byte[] _bytesConnectionClose = Encoding.ASCII.GetBytes("\r\nConnection: close");

src/Servers/Kestrel/Core/src/Internal/Http/IHttpOutputProducer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
77

8+
/// <remarks>
9+
/// Used to plug HTTP version-specific functionality into <see cref="HttpProtocol"/>.
10+
/// </remarks>
811
internal interface IHttpOutputProducer
912
{
1013
ValueTask<FlushResult> WriteChunkAsync(ReadOnlySpan<byte> data, CancellationToken cancellationToken);
@@ -13,6 +16,7 @@ internal interface IHttpOutputProducer
1316
void WriteResponseHeaders(int statusCode, string? reasonPhrase, HttpResponseHeaders responseHeaders, bool autoChunk, bool appCompleted);
1417
// This takes ReadOnlySpan instead of ReadOnlyMemory because it always synchronously copies data before flushing.
1518
ValueTask<FlushResult> WriteDataToPipeAsync(ReadOnlySpan<byte> data, CancellationToken cancellationToken);
19+
// Test hook
1620
Task WriteDataAsync(ReadOnlySpan<byte> data, CancellationToken cancellationToken);
1721
ValueTask<FlushResult> WriteStreamSuffixAsync();
1822
void Advance(int bytes);

src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/FlowControl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl;
77

8+
/// <summary>
9+
/// Represents the flow control window for an <see cref="InputFlowControl"/>.
10+
/// Mutated as the available quota changes.
11+
/// </summary>
12+
/// <remarks>
13+
/// "FlowControlWindow" would probably be a clearer name.
14+
/// </remarks>
815
internal struct FlowControl
916
{
1017
public FlowControl(uint initialWindowSize)

src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/InputFlowControl.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl;
77

8+
/// <summary>
9+
/// Represents the in-bound flow control state of a stream or connection.
10+
/// </summary>
11+
/// <remarks>
12+
/// Owns a <see cref="FlowControl"/> that it uses to track the present window size.
13+
/// <para/>
14+
/// <see cref="Http2Connection"/> owns an instance for the connection-level flow control.
15+
/// <see cref="StreamInputFlowControl"/> owns an instance for the stream-level flow control.
16+
/// <para/>
17+
/// Reusable after calling <see cref="Reset"/>.
18+
/// </remarks>
19+
/// <seealso href="https://datatracker.ietf.org/doc/html/rfc9113#name-flow-control"/>
820
internal sealed class InputFlowControl
921
{
1022
private readonly int _initialWindowSize;

src/Servers/Kestrel/Core/src/Internal/Http2/FlowControl/StreamInputFlowControl.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.FlowControl;
77

8+
/// <summary>
9+
/// Represents the in-bound flow control state of a stream.
10+
/// </summary>
11+
/// <remarks>
12+
/// Owns an <see cref="InputFlowControl"/> for the stream-level flow control and
13+
/// references another (owned by a <see cref="Http2Connection"/>) for the
14+
/// connection-level flow control.
15+
/// <para/>
16+
/// <see cref="Http2Stream"/> owns an instance for the stream-level flow control.
17+
/// <para/>
18+
/// Reusable after calling <see cref="Reset"/>.
19+
/// </remarks>
20+
/// <seealso href="https://datatracker.ietf.org/doc/html/rfc9113#name-flow-control"/>
821
internal sealed class StreamInputFlowControl
922
{
1023
private readonly InputFlowControl _connectionLevelFlowControl;

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121

2222
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
2323

24+
/// <summary>
25+
/// An HTTP/2 connection - owns the request processing and lifetime.
26+
/// <para/>
27+
/// Responsible for reading incoming HTTP/2 frames. New requests create streams and execution
28+
/// for the request is dispatched to the thread pool.
29+
/// <para/>
30+
/// </summary>
31+
/// <remarks>
32+
/// Owned by <see cref="HttpConnection"/>.
33+
/// <para/>
34+
/// For performance, streams are pooled when an HTTP/2 request completes gracefully. Future requests
35+
/// reuse a pooled stream if available. There are limits on the number of pooled streams, and unused
36+
/// streams are automatically removed from the pool after a timeout.
37+
/// <para/>
38+
/// The connection itself is not reusable.
39+
/// </remarks>
2440
internal sealed partial class Http2Connection : IHttp2StreamLifetimeHandler, IHttpStreamHeadersHandler, IRequestProcessor
2541
{
2642
// This uses C# compiler's ability to refer to static data directly. For more information see https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414

1515
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
1616

17+
/// <summary>
18+
/// Encodes HTTP/2 stream responses as frames and sends them over the wire.
19+
/// </summary>
20+
/// <remarks>
21+
/// Owned by <see cref="Http2Connection"/>.
22+
/// <para/>
23+
/// Since a connection has multiple streams, this class maintains a <see cref="Channel{T}"/> (i.e. bounded queue)
24+
/// of <see cref="Http2OutputProducer"/> instances (each of which is owned by a stream) that want to write frames.
25+
/// <para/>
26+
/// Reuses a single <see cref="Http2Frame"/>, which it populates based on the next <see cref="Http2OutputProducer"/>
27+
/// (and corresponding <see cref="Http2Stream{TContext}"/>) and then serializes to binary in
28+
/// <see cref="WriteToOutputPipe"/>.
29+
/// <para/>
30+
/// Tracks the outgoing connection window size while <see cref="Http2OutputProducer"/> tracks the stream window size.
31+
/// </remarks>
1732
internal sealed class Http2FrameWriter
1833
{
1934
// Literal Header Field without Indexing - Indexed Name (Index 8 - :status)

src/Servers/Kestrel/Core/src/Internal/Http2/Http2KeepAlive.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ internal enum KeepAliveState
1313
Timeout
1414
}
1515

16+
/// <summary>
17+
/// Used by a <see cref="Http2Connection"/> to determine whether the connection is still alive.
18+
/// If no frames have been received within a given period of time, triggers a ping that should
19+
/// draw a response. After a further timeout, signals that the connection should be dropped.
20+
/// </summary>
1621
internal sealed class Http2KeepAlive
1722
{
1823
// An empty ping payload

src/Servers/Kestrel/Core/src/Internal/Http2/Http2MessageBody.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
1212

13+
/// <summary>
14+
/// Exposes the bytes of an incoming request.
15+
/// </summary>
16+
/// <remarks>
17+
/// Owned by an <see cref="Http2Stream"/>.
18+
/// <para/>
19+
/// Reusable after calling <see cref="Reset"/>.
20+
/// </remarks>
1321
internal sealed class Http2MessageBody : MessageBody
1422
{
1523
private readonly Http2Stream _context;

src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
1414

15+
/// <remarks>
16+
/// Owned by <see cref="Http2Stream"/>.
17+
/// <para/>
18+
/// Tracks the outgoing stream flow control window.
19+
/// <para/>
20+
/// Reusable after calling <see cref="StreamReset"/> (<see cref="Reset"/> is unrelated and does nothing).
21+
/// </remarks>
1522
internal sealed class Http2OutputProducer : IHttpOutputProducer, IHttpOutputAborter, IDisposable
1623
{
1724
private int StreamId => _stream.StreamId;

0 commit comments

Comments
 (0)