Skip to content

Commit dd476b1

Browse files
authored
HTTP/3: Update generated transport features (#34757)
1 parent e52f8e8 commit dd476b1

13 files changed

+195
-54
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17213,4 +17213,4 @@ public bool MoveNext()
1721317213
}
1721417214
}
1721517215
}
17216-
}
17216+
}

src/Servers/Kestrel/Transport.Quic/src/Internal/FakeTlsConnectionFeature.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net.Sockets;
5+
using System.Security.Cryptography.X509Certificates;
6+
using Microsoft.AspNetCore.Connections;
7+
using Microsoft.AspNetCore.Connections.Features;
8+
using Microsoft.AspNetCore.Http.Features;
9+
10+
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
11+
{
12+
internal sealed partial class QuicConnectionContext : IProtocolErrorCodeFeature, ITlsConnectionFeature
13+
{
14+
public long Error { get; set; }
15+
16+
// Support accessing client certificate
17+
// https://github.com/dotnet/aspnetcore/issues/34756
18+
public X509Certificate2? ClientCertificate
19+
{
20+
get => throw new NotSupportedException();
21+
set => throw new NotSupportedException();
22+
}
23+
24+
public Task<X509Certificate2?> GetClientCertificateAsync(CancellationToken cancellationToken)
25+
{
26+
throw new NotSupportedException();
27+
}
28+
29+
private void InitializeFeatures()
30+
{
31+
_currentIProtocolErrorCodeFeature = this;
32+
_currentITlsConnectionFeature = this;
33+
}
34+
}
35+
}

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionContext.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
1515
{
16-
internal class QuicConnectionContext : TransportMultiplexedConnection, IProtocolErrorCodeFeature
16+
internal partial class QuicConnectionContext : TransportMultiplexedConnection
1717
{
1818
// Internal for testing.
1919
internal PooledStreamStack<QuicStreamContext> StreamPool;
@@ -30,8 +30,6 @@ internal class QuicConnectionContext : TransportMultiplexedConnection, IProtocol
3030

3131
private Task? _closeTask;
3232

33-
public long Error { get; set; }
34-
3533
internal const int InitialStreamPoolSize = 5;
3634
internal const int MaxStreamPoolSize = 100;
3735
internal const long StreamPoolExpiryTicks = TimeSpan.TicksPerSecond * 5;
@@ -42,10 +40,10 @@ public QuicConnectionContext(QuicConnection connection, QuicTransportContext con
4240
_context = context;
4341
_connection = connection;
4442
ConnectionClosed = _connectionClosedTokenSource.Token;
45-
Features.Set<ITlsConnectionFeature>(new FakeTlsConnectionFeature());
46-
Features.Set<IProtocolErrorCodeFeature>(this);
4743

4844
StreamPool = new PooledStreamStack<QuicStreamContext>(InitialStreamPoolSize);
45+
46+
InitializeFeatures();
4947
}
5048

5149
public override async ValueTask DisposeAsync()

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.FeatureCollection.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77

88
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
99
{
10-
internal sealed partial class QuicStreamContext : IPersistentStateFeature
10+
internal sealed partial class QuicStreamContext : IPersistentStateFeature, IStreamDirectionFeature, IProtocolErrorCodeFeature, IStreamIdFeature
1111
{
1212
private IDictionary<object, object?>? _persistentState;
1313

14+
public bool CanRead { get; private set; }
15+
public bool CanWrite { get; private set; }
16+
17+
public long Error { get; set; }
18+
19+
public long StreamId { get; private set; }
20+
1421
IDictionary<object, object?> IPersistentStateFeature.State
1522
{
1623
get
@@ -23,6 +30,10 @@ internal sealed partial class QuicStreamContext : IPersistentStateFeature
2330
private void InitializeFeatures()
2431
{
2532
_currentIPersistentStateFeature = this;
33+
_currentIStreamDirectionFeature = this;
34+
_currentIProtocolErrorCodeFeature = this;
35+
_currentIStreamIdFeature = this;
36+
_currentITlsConnectionFeature = _connection._currentITlsConnectionFeature;
2637
}
2738
}
2839
}

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
1919
{
20-
internal partial class QuicStreamContext : TransportConnection, IStreamDirectionFeature, IProtocolErrorCodeFeature, IStreamIdFeature, IPooledStream
20+
internal partial class QuicStreamContext : TransportConnection, IPooledStream
2121
{
2222
// Internal for testing.
2323
internal Task _processingTask = Task.CompletedTask;
@@ -70,10 +70,6 @@ public QuicStreamContext(QuicConnectionContext connection, QuicTransportContext
7070
private PipeWriter Input => Application.Output;
7171
private PipeReader Output => Application.Input;
7272

73-
public bool CanRead { get; private set; }
74-
public bool CanWrite { get; private set; }
75-
76-
public long StreamId { get; private set; }
7773
public bool CanReuse { get; private set; }
7874

7975
public void Initialize(QuicStream stream)
@@ -89,13 +85,6 @@ public void Initialize(QuicStream stream)
8985

9086
ConnectionClosed = _streamClosedTokenSource.Token;
9187

92-
// TODO - add to generated features
93-
Features.Set<IStreamDirectionFeature>(this);
94-
Features.Set<IProtocolErrorCodeFeature>(this);
95-
Features.Set<IStreamIdFeature>(this);
96-
// TODO populate the ITlsConnectionFeature (requires client certs).
97-
Features.Set<ITlsConnectionFeature>(new FakeTlsConnectionFeature());
98-
9988
InitializeFeatures();
10089

10190
CanRead = _stream.CanRead;
@@ -134,8 +123,6 @@ public override string ConnectionId
134123
set => _connectionId = value;
135124
}
136125

137-
public long Error { get; set; }
138-
139126
public long PoolExpirationTicks { get; set; }
140127

141128
public void Start()

src/Servers/Kestrel/shared/KnownHeaders.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,7 @@ public bool MoveNext()
13381338
}}
13391339
")}}}";
13401340

1341-
// Temporary workaround for https://github.com/dotnet/runtime/issues/55688
1342-
return s.Replace("{{", "{").Replace("}}", "}");
1341+
return s;
13431342
}
13441343

13451344
private static string GetHeaderLookup()

src/Servers/Kestrel/shared/TransportConnection.Generated.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ internal partial class TransportConnection : IFeatureCollection,
3030
// Other reserved feature slots
3131
internal protected IPersistentStateFeature? _currentIPersistentStateFeature;
3232
internal protected IConnectionSocketFeature? _currentIConnectionSocketFeature;
33+
internal protected IProtocolErrorCodeFeature? _currentIProtocolErrorCodeFeature;
34+
internal protected IStreamDirectionFeature? _currentIStreamDirectionFeature;
35+
internal protected IStreamIdFeature? _currentIStreamIdFeature;
36+
internal protected ITlsConnectionFeature? _currentITlsConnectionFeature;
3337

3438
private int _featureRevision;
3539

@@ -45,6 +49,10 @@ private void FastReset()
4549

4650
_currentIPersistentStateFeature = null;
4751
_currentIConnectionSocketFeature = null;
52+
_currentIProtocolErrorCodeFeature = null;
53+
_currentIStreamDirectionFeature = null;
54+
_currentIStreamIdFeature = null;
55+
_currentITlsConnectionFeature = null;
4856
}
4957

5058
// Internal for testing
@@ -144,6 +152,22 @@ private void ExtraFeatureSet(Type key, object? value)
144152
{
145153
feature = _currentIConnectionSocketFeature;
146154
}
155+
else if (key == typeof(IProtocolErrorCodeFeature))
156+
{
157+
feature = _currentIProtocolErrorCodeFeature;
158+
}
159+
else if (key == typeof(IStreamDirectionFeature))
160+
{
161+
feature = _currentIStreamDirectionFeature;
162+
}
163+
else if (key == typeof(IStreamIdFeature))
164+
{
165+
feature = _currentIStreamIdFeature;
166+
}
167+
else if (key == typeof(ITlsConnectionFeature))
168+
{
169+
feature = _currentITlsConnectionFeature;
170+
}
147171
else if (MaybeExtra != null)
148172
{
149173
feature = ExtraFeatureGet(key);
@@ -184,6 +208,22 @@ private void ExtraFeatureSet(Type key, object? value)
184208
{
185209
_currentIConnectionSocketFeature = (IConnectionSocketFeature?)value;
186210
}
211+
else if (key == typeof(IProtocolErrorCodeFeature))
212+
{
213+
_currentIProtocolErrorCodeFeature = (IProtocolErrorCodeFeature?)value;
214+
}
215+
else if (key == typeof(IStreamDirectionFeature))
216+
{
217+
_currentIStreamDirectionFeature = (IStreamDirectionFeature?)value;
218+
}
219+
else if (key == typeof(IStreamIdFeature))
220+
{
221+
_currentIStreamIdFeature = (IStreamIdFeature?)value;
222+
}
223+
else if (key == typeof(ITlsConnectionFeature))
224+
{
225+
_currentITlsConnectionFeature = (ITlsConnectionFeature?)value;
226+
}
187227
else
188228
{
189229
ExtraFeatureSet(key, value);
@@ -226,6 +266,22 @@ private void ExtraFeatureSet(Type key, object? value)
226266
{
227267
feature = Unsafe.As<IConnectionSocketFeature?, TFeature?>(ref _currentIConnectionSocketFeature);
228268
}
269+
else if (typeof(TFeature) == typeof(IProtocolErrorCodeFeature))
270+
{
271+
feature = Unsafe.As<IProtocolErrorCodeFeature?, TFeature?>(ref _currentIProtocolErrorCodeFeature);
272+
}
273+
else if (typeof(TFeature) == typeof(IStreamDirectionFeature))
274+
{
275+
feature = Unsafe.As<IStreamDirectionFeature?, TFeature?>(ref _currentIStreamDirectionFeature);
276+
}
277+
else if (typeof(TFeature) == typeof(IStreamIdFeature))
278+
{
279+
feature = Unsafe.As<IStreamIdFeature?, TFeature?>(ref _currentIStreamIdFeature);
280+
}
281+
else if (typeof(TFeature) == typeof(ITlsConnectionFeature))
282+
{
283+
feature = Unsafe.As<ITlsConnectionFeature?, TFeature?>(ref _currentITlsConnectionFeature);
284+
}
229285
else if (MaybeExtra != null)
230286
{
231287
feature = (TFeature?)(ExtraFeatureGet(typeof(TFeature)));
@@ -269,6 +325,22 @@ private void ExtraFeatureSet(Type key, object? value)
269325
{
270326
_currentIConnectionSocketFeature = Unsafe.As<TFeature?, IConnectionSocketFeature?>(ref feature);
271327
}
328+
else if (typeof(TFeature) == typeof(IProtocolErrorCodeFeature))
329+
{
330+
_currentIProtocolErrorCodeFeature = Unsafe.As<TFeature?, IProtocolErrorCodeFeature?>(ref feature);
331+
}
332+
else if (typeof(TFeature) == typeof(IStreamDirectionFeature))
333+
{
334+
_currentIStreamDirectionFeature = Unsafe.As<TFeature?, IStreamDirectionFeature?>(ref feature);
335+
}
336+
else if (typeof(TFeature) == typeof(IStreamIdFeature))
337+
{
338+
_currentIStreamIdFeature = Unsafe.As<TFeature?, IStreamIdFeature?>(ref feature);
339+
}
340+
else if (typeof(TFeature) == typeof(ITlsConnectionFeature))
341+
{
342+
_currentITlsConnectionFeature = Unsafe.As<TFeature?, ITlsConnectionFeature?>(ref feature);
343+
}
272344
else
273345
{
274346
ExtraFeatureSet(typeof(TFeature), feature);
@@ -305,6 +377,22 @@ private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()
305377
{
306378
yield return new KeyValuePair<Type, object>(typeof(IConnectionSocketFeature), _currentIConnectionSocketFeature);
307379
}
380+
if (_currentIProtocolErrorCodeFeature != null)
381+
{
382+
yield return new KeyValuePair<Type, object>(typeof(IProtocolErrorCodeFeature), _currentIProtocolErrorCodeFeature);
383+
}
384+
if (_currentIStreamDirectionFeature != null)
385+
{
386+
yield return new KeyValuePair<Type, object>(typeof(IStreamDirectionFeature), _currentIStreamDirectionFeature);
387+
}
388+
if (_currentIStreamIdFeature != null)
389+
{
390+
yield return new KeyValuePair<Type, object>(typeof(IStreamIdFeature), _currentIStreamIdFeature);
391+
}
392+
if (_currentITlsConnectionFeature != null)
393+
{
394+
yield return new KeyValuePair<Type, object>(typeof(ITlsConnectionFeature), _currentITlsConnectionFeature);
395+
}
308396

309397
if (MaybeExtra != null)
310398
{

0 commit comments

Comments
 (0)