Skip to content

Commit

Permalink
Merge branch 'release/6.0' into merge/release/6.0-rc1-to-release/6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm authored Aug 24, 2021
2 parents d571f82 + 8da7b81 commit 5e092de
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 241 deletions.
15 changes: 15 additions & 0 deletions eng/SourceBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,19 @@
</PropertyGroup>
</Target>

<Target Name="GetAspnetcoreCategorizedIntermediateNupkgContents"
BeforeTargets="GetCategorizedIntermediateNupkgContents">
<PropertyGroup>
<InstallersArtifactsDir>$(CurrentRepoSourceBuildArtifactsDir)\installers\$(Configuration)\</InstallersArtifactsDir>
</PropertyGroup>

<ItemGroup>
<!--
Add the internal installers artifacts required by dotnet/installer.
-->
<IntermediateNupkgArtifactFile Include="$(InstallersArtifactsDir)aspnetcore-runtime-internal-*.tar.gz" />
<IntermediateNupkgArtifactFile Include="$(InstallersArtifactsDir)aspnetcore_base_runtime.version" />
</ItemGroup>
</Target>

</Project>
280 changes: 140 additions & 140 deletions eng/Version.Details.xml

Large diffs are not rendered by default.

142 changes: 71 additions & 71 deletions eng/Versions.props

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Servers/HttpSys/src/RequestProcessing/RequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public void Abort()
}
_requestAbortSource.Dispose();
}
else
{
_disconnectToken = new CancellationToken(canceled: true);
}
ForceCancelRequest();
Request.Dispose();
// Only Abort, Response.Dispose() tries a graceful flush
Expand Down
95 changes: 95 additions & 0 deletions src/Servers/HttpSys/test/FunctionalTests/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,101 @@ public async Task Request_EscapedControlCharacters_400()
}
}

[ConditionalFact]
public async Task RequestAborted_AfterAccessingProperty_Notified()
{
var registered = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var result = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
using var server = Utilities.CreateHttpServerReturnRoot("/", out var address, async httpContext =>
{
var ct = httpContext.RequestAborted;

if (!ct.CanBeCanceled || ct.IsCancellationRequested)
{
result.SetException(new Exception("The CT isn't valid."));
return;
}

ct.Register(() => result.SetResult());

registered.SetResult();

// Don't exit until it fires or else it could be disposed.
await result.Task.DefaultTimeout();
});

// Send a request and then abort.

var uri = new Uri(address);
StringBuilder builder = new StringBuilder();
builder.AppendLine("POST / HTTP/1.1");
builder.AppendLine("Connection: close");
builder.AppendLine("Content-Length: 10");
builder.Append("HOST: ");
builder.AppendLine(uri.Authority);
builder.AppendLine();

byte[] request = Encoding.ASCII.GetBytes(builder.ToString());

using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);

await socket.ConnectAsync(uri.Host, uri.Port);
socket.Send(request);

// Wait for the token to be setup before aborting.
await registered.Task.DefaultTimeout();

socket.Close();

await result.Task.DefaultTimeout();
}

[ConditionalFact]
public async Task RequestAbortedDurringRead_BeforeAccessingProperty_TokenAlreadyCanceled()
{
var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var result = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
using var server = Utilities.CreateHttpServerReturnRoot("/", out var address, async httpContext =>
{
await requestAborted.Task.DefaultTimeout();
try
{
await httpContext.Request.Body.ReadAsync(new byte[10]).DefaultTimeout();
result.SetException(new Exception("This should have aborted"));
return;
}
catch (IOException)
{
}

result.SetResult(httpContext.RequestAborted.IsCancellationRequested);
});

// Send a request and then abort.

var uri = new Uri(address);
StringBuilder builder = new StringBuilder();
builder.AppendLine("POST / HTTP/1.1");
builder.AppendLine("Connection: close");
builder.AppendLine("Content-Length: 10");
builder.Append("HOST: ");
builder.AppendLine(uri.Authority);
builder.AppendLine();

byte[] request = Encoding.ASCII.GetBytes(builder.ToString());

using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);

await socket.ConnectAsync(uri.Host, uri.Port);
socket.Send(request);
socket.Close();

requestAborted.SetResult();

var wasCancelled = await result.Task;
Assert.True(wasCancelled);
}

private IServer CreateServer(out string root, RequestDelegate app)
{
// TODO: We're just doing this to get a dynamic port. This can be removed later when we add support for hot-adding prefixes.
Expand Down
9 changes: 9 additions & 0 deletions src/Servers/Kestrel/Core/src/ListenOptionsHttpsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public static ListenOptions UseHttps(this ListenOptions listenOptions, ServerOpt
/// <returns>The <see cref="ListenOptions"/>.</returns>
public static ListenOptions UseHttps(this ListenOptions listenOptions, ServerOptionsSelectionCallback serverOptionsSelectionCallback, object state, TimeSpan handshakeTimeout)
{
if (listenOptions.Protocols.HasFlag(HttpProtocols.Http3))
{
throw new NotSupportedException($"{nameof(UseHttps)} with {nameof(ServerOptionsSelectionCallback)} is not supported with HTTP/3.");
}
return listenOptions.UseHttps(new TlsHandshakeCallbackOptions()
{
OnConnection = context => serverOptionsSelectionCallback(context.SslStream, context.ClientHelloInfo, context.State, context.CancellationToken),
Expand Down Expand Up @@ -283,6 +287,11 @@ public static ListenOptions UseHttps(this ListenOptions listenOptions, TlsHandsh
throw new ArgumentException($"{nameof(TlsHandshakeCallbackOptions.OnConnection)} must not be null.");
}

if (listenOptions.Protocols.HasFlag(HttpProtocols.Http3))
{
throw new NotSupportedException($"{nameof(UseHttps)} with {nameof(TlsHandshakeCallbackOptions)} is not supported with HTTP/3.");
}

var loggerFactory = listenOptions.KestrelServerOptions?.ApplicationServices.GetRequiredService<ILoggerFactory>() ?? NullLoggerFactory.Instance;

listenOptions.IsTls = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ private static bool IsWindowsVersionIncompatibleWithHttp2()

internal static SslServerAuthenticationOptions CreateHttp3Options(HttpsConnectionAdapterOptions httpsOptions)
{
if (httpsOptions.OnAuthenticate != null)
{
throw new NotSupportedException($"The {nameof(HttpsConnectionAdapterOptions.OnAuthenticate)} callback is not supported with HTTP/3.");
}

// TODO Set other relevant values on options
var sslServerAuthenticationOptions = new SslServerAuthenticationOptions
{
Expand Down
60 changes: 30 additions & 30 deletions src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,44 +593,44 @@ public async Task Http3_NoUseHttps_Throws()
}

[Fact]
public async Task Http3_UseHttp3Callback_NoSslServerOptions()
public void Http3_ServerOptionsSelectionCallback_Throws()
{
var serverOptions = CreateServerOptions();
serverOptions.DefaultCertificate = _x509Certificate2;

IFeatureCollection bindFeatures = null;
var multiplexedConnectionListenerFactory = new MockMultiplexedConnectionListenerFactory();
multiplexedConnectionListenerFactory.OnBindAsync = (ep, features) =>
serverOptions.ListenLocalhost(5001, options =>
{
bindFeatures = features;
};

var testContext = new TestServiceContext(LoggerFactory);
testContext.ServerOptions = serverOptions;
await using (var server = new TestServer(context => Task.CompletedTask,
testContext,
serverOptions =>
{
serverOptions.ListenLocalhost(5001, listenOptions =>
options.Protocols = HttpProtocols.Http3;
var exception = Assert.Throws<NotSupportedException>(() =>
options.UseHttps((SslStream stream, SslClientHelloInfo clientHelloInfo, object state, CancellationToken cancellationToken) =>
{
listenOptions.Protocols = HttpProtocols.Http3;
listenOptions.UseHttps((SslStream stream, SslClientHelloInfo clientHelloInfo, object state, CancellationToken cancellationToken) =>
{
return ValueTask.FromResult((new SslServerAuthenticationOptions()));
}, state: null);
});
},
services =>
{
services.AddSingleton<IMultiplexedConnectionListenerFactory>(multiplexedConnectionListenerFactory);
}))
{
}
return ValueTask.FromResult((new SslServerAuthenticationOptions()));
}, state: null)
);
Assert.Equal("UseHttps with ServerOptionsSelectionCallback is not supported with HTTP/3.", exception.Message);
});
}

Assert.NotNull(bindFeatures);
[Fact]
public void Http3_TlsHandshakeCallbackOptions_Throws()
{
var serverOptions = CreateServerOptions();
serverOptions.DefaultCertificate = _x509Certificate2;

var sslOptions = bindFeatures.Get<SslServerAuthenticationOptions>();
Assert.Null(sslOptions);
serverOptions.ListenLocalhost(5001, options =>
{
options.Protocols = HttpProtocols.Http3;
var exception = Assert.Throws<NotSupportedException>(() =>
options.UseHttps(new TlsHandshakeCallbackOptions()
{
OnConnection = context =>
{
return ValueTask.FromResult(new SslServerAuthenticationOptions());
}
})
);
Assert.Equal("UseHttps with TlsHandshakeCallbackOptions is not supported with HTTP/3.", exception.Message);
});
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,33 @@ public async Task ClientCertificate_Allow_NotAvailable_Optional()
await host.StopAsync().DefaultTimeout();
}

[ConditionalFact]
[MsQuicSupported]
public async Task OnAuthentice_Available_Throws()
{
var builder = CreateHostBuilder(async context =>
{
await context.Response.WriteAsync("Hello World");
}, configureKestrel: kestrelOptions =>
{
kestrelOptions.ListenAnyIP(0, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http3;
listenOptions.UseHttps(httpsOptions =>
{
httpsOptions.OnAuthenticate = (_, _) => { };
});
});
});

using var host = builder.Build();
using var client = Http3Helpers.CreateClient();

var exception = await Assert.ThrowsAsync<NotSupportedException>(() =>
host.StartAsync().DefaultTimeout());
Assert.Equal("The OnAuthenticate callback is not supported with HTTP/3.", exception.Message);
}

private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null)
{
return Http3Helpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel);
Expand Down

0 comments on commit 5e092de

Please sign in to comment.