IISHttpContext.FeatureCollection.Protocol recognizes HTTP/2 (#14412)
This commit is contained in:
parent
0d412c3775
commit
752d99ca53
|
|
@ -174,23 +174,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
{
|
{
|
||||||
if (IsNotInitialized(Fields.Protocol))
|
if (IsNotInitialized(Fields.Protocol))
|
||||||
{
|
{
|
||||||
var protocol = Request.ProtocolVersion;
|
_httpProtocolVersion = Request.ProtocolVersion.GetHttpProtocolVersion();
|
||||||
if (protocol == Constants.V2)
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/2";
|
|
||||||
}
|
|
||||||
else if (protocol == Constants.V1_1)
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/1.1";
|
|
||||||
}
|
|
||||||
else if (protocol == Constants.V1_0)
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/1.0";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/" + protocol.ToString(2);
|
|
||||||
}
|
|
||||||
SetInitialized(Fields.Protocol);
|
SetInitialized(Fields.Protocol);
|
||||||
}
|
}
|
||||||
return _httpProtocolVersion;
|
return _httpProtocolVersion;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Http.Features.Authentication;
|
using Microsoft.AspNetCore.Http.Features.Authentication;
|
||||||
|
using Microsoft.AspNetCore.HttpSys.Internal;
|
||||||
using Microsoft.AspNetCore.Server.IIS.Core.IO;
|
using Microsoft.AspNetCore.Server.IIS.Core.IO;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
// then the list of `implementedFeatures` in the generated code project MUST also be updated.
|
// then the list of `implementedFeatures` in the generated code project MUST also be updated.
|
||||||
|
|
||||||
private int _featureRevision;
|
private int _featureRevision;
|
||||||
private string _httpProtocolVersion = null;
|
private string _httpProtocolVersion;
|
||||||
private X509Certificate2 _certificate;
|
private X509Certificate2 _certificate;
|
||||||
|
|
||||||
private List<KeyValuePair<Type, object>> MaybeExtra;
|
private List<KeyValuePair<Type, object>> MaybeExtra;
|
||||||
|
|
@ -86,30 +87,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
|
|
||||||
string IHttpRequestFeature.Protocol
|
string IHttpRequestFeature.Protocol
|
||||||
{
|
{
|
||||||
get
|
get => _httpProtocolVersion ??= HttpVersion.GetHttpProtocolVersion();
|
||||||
{
|
set => _httpProtocolVersion = value;
|
||||||
if (_httpProtocolVersion == null)
|
|
||||||
{
|
|
||||||
var protocol = HttpVersion;
|
|
||||||
if (protocol.Major == 1 && protocol.Minor == 1)
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/1.1";
|
|
||||||
}
|
|
||||||
else if (protocol.Major == 1 && protocol.Minor == 0)
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/1.0";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = "HTTP/" + protocol.ToString(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _httpProtocolVersion;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_httpProtocolVersion = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string IHttpRequestFeature.Scheme
|
string IHttpRequestFeature.Scheme
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
|
||||||
internal const string SchemeDelimiter = "://";
|
internal const string SchemeDelimiter = "://";
|
||||||
internal const string DefaultServerAddress = "http://localhost:5000";
|
internal const string DefaultServerAddress = "http://localhost:5000";
|
||||||
|
|
||||||
internal static Version V1_0 = new Version(1, 0);
|
internal static readonly Version V1_0 = new Version(1, 0);
|
||||||
internal static Version V1_1 = new Version(1, 1);
|
internal static readonly Version V1_1 = new Version(1, 1);
|
||||||
internal static Version V2 = new Version(2, 0);
|
internal static readonly Version V2 = new Version(2, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// 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.HttpSys.Internal
|
||||||
|
{
|
||||||
|
internal static class Extensions
|
||||||
|
{
|
||||||
|
public static string GetHttpProtocolVersion(this Version version) => version switch
|
||||||
|
{
|
||||||
|
{ Major: 2, Minor: 0 } => "HTTP/2",
|
||||||
|
{ Major: 1, Minor: 1 } => "HTTP/1.1",
|
||||||
|
{ Major: 1, Minor: 0 } => "HTTP/1.0",
|
||||||
|
_ => "HTTP/" + version.ToString(2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue