Revert "Change ApplicationProtocol to ReadOnlyMemory<byte> #2182"

This reverts commit 2d3a01d48d.
This commit is contained in:
Stephen Halter 2018-01-04 16:17:36 -08:00
parent bd3195ff43
commit 664055fa43
7 changed files with 22 additions and 15 deletions

View File

@ -15,9 +15,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="testCert.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="../../test/shared/TestCertificates/testCert.pfx" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>

Binary file not shown.

View File

@ -1,12 +1,11 @@
// 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
{
ReadOnlyMemory<byte> ApplicationProtocol { get; }
string ApplicationProtocol { get; }
}
}

View File

@ -23,8 +23,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
{
public class HttpConnection : ITimeoutControl, IConnectionTimeoutFeature, IRequestProcessor
{
private static readonly ReadOnlyMemory<byte> Http2Id = new ReadOnlyMemory<byte>(new[] { (byte)'h', (byte)'2' });
private readonly HttpConnectionContext _context;
private readonly TaskCompletionSource<object> _socketClosedTcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -305,8 +303,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
private HttpProtocols SelectProtocol()
{
var hasTls = _context.ConnectionFeatures.Get<ITlsConnectionFeature>() != null;
var applicationProtocol = _context.ConnectionFeatures.Get<ITlsApplicationProtocolFeature>()?.ApplicationProtocol
?? new ReadOnlyMemory<byte>();
var applicationProtocol = _context.ConnectionFeatures.Get<ITlsApplicationProtocolFeature>()?.ApplicationProtocol;
var http1Enabled = (_context.Protocols & HttpProtocols.Http1) == HttpProtocols.Http1;
var http2Enabled = (_context.Protocols & HttpProtocols.Http2) == HttpProtocols.Http2;
@ -322,7 +319,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
error = CoreStrings.EndPointRequiresTlsForHttp1AndHttp2;
}
if (!http1Enabled && http2Enabled && hasTls && !Http2Id.SequenceEqual(applicationProtocol))
if (!http1Enabled && http2Enabled && hasTls && applicationProtocol != "h2")
{
error = CoreStrings.EndPointHttp2NotNegotiated;
}
@ -333,7 +330,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
return HttpProtocols.None;
}
return http2Enabled && (!hasTls || Http2Id.SequenceEqual(applicationProtocol)) ? HttpProtocols.Http2 : HttpProtocols.Http1;
return http2Enabled && (!hasTls || applicationProtocol == "h2") ? HttpProtocols.Http2 : HttpProtocols.Http1;
}
public void Tick(DateTimeOffset now)

View File

@ -160,7 +160,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
}
#if NETCOREAPP2_1
feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol;
// 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();
}
context.Features.Set<ITlsApplicationProtocolFeature>(feature);
#endif
feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate);

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
{
public X509Certificate2 ClientCertificate { get; set; }
public ReadOnlyMemory<byte> ApplicationProtocol { get; set; }
public string ApplicationProtocol { get; set; }
public Task<X509Certificate2> GetClientCertificateAsync(CancellationToken cancellationToken)
{

View File

@ -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>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;kestrel</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>