Change ApplicationProtocol to ReadOnlyMemory<byte> #2182
This commit is contained in:
parent
664055fa43
commit
ad2149f5f0
|
|
@ -15,7 +15,9 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="../../test/shared/TestCertificates/testCert.pfx" CopyToOutputDirectory="PreserveNewest" />
|
||||
<Content Include="testCert.pfx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,11 +1,12 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Features
|
||||
{
|
||||
// TODO: this should be merged with ITlsConnectionFeature
|
||||
public interface ITlsApplicationProtocolFeature
|
||||
{
|
||||
string ApplicationProtocol { get; }
|
||||
ReadOnlyMemory<byte> ApplicationProtocol { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
{
|
||||
public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor
|
||||
{
|
||||
private static readonly ReadOnlyMemory<byte> Http2Id = new[] { (byte)'h', (byte)'2' };
|
||||
|
||||
private readonly HttpConnectionContext _context;
|
||||
private readonly TaskCompletionSource<object> _socketClosedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
|
|
@ -303,7 +305,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
private HttpProtocols SelectProtocol()
|
||||
{
|
||||
var hasTls = _context.ConnectionFeatures.Get<ITlsConnectionFeature>() != null;
|
||||
var applicationProtocol = _context.ConnectionFeatures.Get<ITlsApplicationProtocolFeature>()?.ApplicationProtocol;
|
||||
var applicationProtocol = _context.ConnectionFeatures.Get<ITlsApplicationProtocolFeature>()?.ApplicationProtocol
|
||||
?? new ReadOnlyMemory<byte>();
|
||||
var http1Enabled = (_context.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1;
|
||||
var http2Enabled = (_context.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2;
|
||||
|
||||
|
|
@ -319,7 +322,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2;
|
||||
}
|
||||
|
||||
if (!http1Enabled && http2Enabled && hasTls && applicationProtocol != "h2")
|
||||
if (!http1Enabled && http2Enabled && hasTls && !Http2Id.Span.SequenceEqual(applicationProtocol.Span))
|
||||
{
|
||||
error = CoreStrings.EndPointHttp2NotNegotiated;
|
||||
}
|
||||
|
|
@ -330,7 +333,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
|
|||
return HttpProtocols.None;
|
||||
}
|
||||
|
||||
return http2Enabled && (!hasTls || applicationProtocol == "h2") ? HttpProtocols.Http2 : HttpProtocols.Http1;
|
||||
return http2Enabled && (!hasTls || Http2Id.Span.SequenceEqual(applicationProtocol.Span)) ? HttpProtocols.Http2 : HttpProtocols.Http1;
|
||||
}
|
||||
|
||||
public void Tick(DateTimeOffset now)
|
||||
|
|
|
|||
|
|
@ -160,20 +160,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
|
|||
}
|
||||
|
||||
#if NETCOREAPP2_1
|
||||
// Don't allocate in the common case, see https://github.com/dotnet/corefx/issues/25432
|
||||
if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http11)
|
||||
{
|
||||
feature.ApplicationProtocol = "http/1.1";
|
||||
}
|
||||
else if (sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2)
|
||||
{
|
||||
feature.ApplicationProtocol = "h2";
|
||||
}
|
||||
else
|
||||
{
|
||||
feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.ToString();
|
||||
}
|
||||
|
||||
feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol;
|
||||
context.Features.Set<ITlsApplicationProtocolFeature>(feature);
|
||||
#endif
|
||||
feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
|
|||
{
|
||||
public X509Certificate2 ClientCertificate { get; set; }
|
||||
|
||||
public string ApplicationProtocol { get; set; }
|
||||
public ReadOnlyMemory<byte> ApplicationProtocol { get; set; }
|
||||
|
||||
public Task<X509Certificate2> GetClientCertificateAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<AssemblyName>Microsoft.AspNetCore.Server.Kestrel.Core</AssemblyName>
|
||||
<RootNamespace>Microsoft.AspNetCore.Server.Kestrel.Core</RootNamespace>
|
||||
<Description>Core components of ASP.NET Core Kestrel cross-platform web server.</Description>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageTags>aspnetcore;kestrel</PackageTags>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
|
|
|||
Loading…
Reference in New Issue