Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public async Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> appl
else
{
stream = (Http3Stream<TContext>)s!;
stream.InitializeWithExistingContext(streamContext.Transport, streamContext.ConnectionId);
stream.InitializeWithExistingContext(streamContext.Transport);
}

_streamLifetimeHandler.OnStreamCreated(stream);
Expand Down Expand Up @@ -377,9 +377,9 @@ public async Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> appl
private Http3StreamContext CreateHttpStreamContext(ConnectionContext streamContext)
{
var httpConnectionContext = new Http3StreamContext(
streamContext.ConnectionId,
protocols: default,
connectionContext: null!, // TODO connection context is null here. Should we set it to anything?
_multiplexedContext.ConnectionId,
HttpProtocols.Http3,
_multiplexedContext,
_context.ServiceContext,
streamContext.Features,
_context.MemoryPool,
Expand Down Expand Up @@ -459,9 +459,9 @@ private async ValueTask<Http3ControlStream> CreateNewUnidirectionalStreamAsync<T
features.Set<IStreamDirectionFeature>(new DefaultStreamDirectionFeature(canRead: false, canWrite: true));
var streamContext = await _multiplexedContext.ConnectAsync(features);
var httpConnectionContext = new Http3StreamContext(
connectionId: streamContext.ConnectionId,
_multiplexedContext.ConnectionId,
HttpProtocols.Http3,
connectionContext: null!, // TODO connection context is null here. Should we set it to anything?
_multiplexedContext,
_context.ServiceContext,
streamContext.Features,
_context.MemoryPool,
Expand Down
7 changes: 2 additions & 5 deletions src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ public void Initialize(Http3StreamContext context)
_frameWriter.Reset(context.Transport.Output, context.ConnectionId);
}

public void InitializeWithExistingContext(IDuplexPipe transport, string connectionId)
public void InitializeWithExistingContext(IDuplexPipe transport)
{
_context.ConnectionId = connectionId;
_context.Transport = transport;
Initialize(_context);
}
Expand Down Expand Up @@ -677,14 +676,12 @@ private void ApplicationAbort(ConnectionAbortedException abortReason, Http3Error

protected override string CreateRequestId()
{
// TODO include stream id.
return ConnectionId;
return _context.StreamContext.ConnectionId;
}

protected override MessageBody CreateMessageBody()
=> Http3MessageBody.For(this);


protected override bool TryParseRequest(ReadResult result, out bool endConnection)
{
endConnection = !TryValidatePseudoHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
using System.Net;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3
{
internal class Http3StreamContext : HttpConnectionContext
{
public Http3StreamContext(
string connectionId,
HttpProtocols protocols,
ConnectionContext connectionContext,
BaseConnectionContext connectionContext,
ServiceContext serviceContext,
IFeatureCollection connectionFeatures,
MemoryPool<byte> memoryPool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class HttpConnectionContext : BaseHttpConnectionContext
public HttpConnectionContext(
string connectionId,
HttpProtocols protocols,
ConnectionContext connectionContext,
BaseConnectionContext connectionContext,
ServiceContext serviceContext,
IFeatureCollection connectionFeatures,
MemoryPool<byte> memoryPool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.Internal
Expand Down Expand Up @@ -129,7 +130,7 @@ public void Initialize(QuicStream stream)

public override string ConnectionId
{
get => _connectionId ??= $"{_connection.ConnectionId}:{StreamId}";
get => _connectionId ??= StringUtilities.ConcatAsHexSuffix(_connection.ConnectionId, ':', (uint)StreamId);
set => _connectionId = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Compile Include="$(KestrelSharedSourceRoot)\CompletionPipeWriter.cs" Link="Internal\CompletionPipeWriter.cs" />
<Compile Include="$(KestrelSharedSourceRoot)\CorrelationIdGenerator.cs" Link="Internal\CorrelationIdGenerator.cs" />
<Compile Include="$(SharedSourceRoot)ServerInfrastructure\DuplexPipe.cs" Link="Internal\DuplexPipe.cs" />
<Compile Include="$(SharedSourceRoot)ServerInfrastructure\StringUtilities.cs" Link="Internal\StringUtilities.cs" />
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.cs" Link="Internal\TransportConnection.cs" />
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.Generated.cs" Link="Internal\TransportConnection.Generated.cs" />
<Compile Include="$(KestrelSharedSourceRoot)\TransportConnection.FeatureCollection.cs" Link="Internal\TransportConnection.FeatureCollection.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/shared/test/TestContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static Http2StreamContext CreateHttp2StreamContext(

public static Http3StreamContext CreateHttp3StreamContext(
string connectionId = null,
ConnectionContext connectionContext = null,
BaseConnectionContext connectionContext = null,
ServiceContext serviceContext = null,
IFeatureCollection connectionFeatures = null,
MemoryPool<byte> memoryPool = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,8 @@ public async Task POST_ClientCancellationUpload_RequestAbortRaised(HttpProtocols
readAsyncTask.SetResult(body.ReadAsync(buffer).AsTask());
}, protocol: protocol);

var httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

using (var host = builder.Build())
using (var client = new HttpClient(httpClientHandler))
using (var client = CreateClient())
{
await host.StartAsync().DefaultTimeout();

Expand Down Expand Up @@ -231,11 +228,8 @@ public async Task GET_ServerAbort_ClientReceivesAbort(HttpProtocols protocol)
writeAsyncTask.SetResult(context.Response.Body.WriteAsync(TestData).AsTask());
}, protocol: protocol);

var httpClientHandler = new HttpClientHandler();
httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

using (var host = builder.Build())
using (var client = new HttpClient(httpClientHandler))
using (var client = CreateClient())
{
await host.StartAsync().DefaultTimeout();

Expand Down Expand Up @@ -338,6 +332,59 @@ public async Task GET_MultipleRequestsInSequence_ReusedState()
}
}

[ConditionalFact]
[MsQuicSupported]
public async Task GET_MultipleRequests_ConnectionAndTraceIdsUpdated()
{
// Arrange
string connectionId = null;
string traceId = null;

var builder = CreateHostBuilder(context =>
{
connectionId = context.Connection.Id;
traceId = context.TraceIdentifier;

return Task.CompletedTask;
});

using (var host = builder.Build())
using (var client = CreateClient())
{
await host.StartAsync();

// Act
var request1 = new HttpRequestMessage(HttpMethod.Get, $"https://127.0.0.1:{host.GetPort()}/");
request1.Version = HttpVersion.Version30;
request1.VersionPolicy = HttpVersionPolicy.RequestVersionExact;

var response1 = await client.SendAsync(request1);
response1.EnsureSuccessStatusCode();

var connectionId1 = connectionId;
var traceId1 = traceId;

var request2 = new HttpRequestMessage(HttpMethod.Get, $"https://127.0.0.1:{host.GetPort()}/");
request2.Version = HttpVersion.Version30;
request2.VersionPolicy = HttpVersionPolicy.RequestVersionExact;

var response2 = await client.SendAsync(request2);
response2.EnsureSuccessStatusCode();

var connectionId2 = connectionId;
var traceId2 = traceId;

// Assert
Assert.True(!string.IsNullOrEmpty(connectionId1), "ConnectionId should have a value.");
Assert.Equal(connectionId1, connectionId2); // ConnectionId unchanged

Assert.Equal($"{connectionId1}:00000000", traceId1);
Assert.Equal($"{connectionId2}:00000004", traceId2);

await host.StopAsync();
}
}

[ConditionalFact]
[MsQuicSupported]
public async Task GET_MultipleRequestsInSequence_ReusedRequestHeaderStrings()
Expand Down