diff --git a/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs index 3cf9d22fac..f2457d0696 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.FeatureCollection.cs @@ -251,13 +251,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http object IFeatureCollection.this[Type key] { - get => FastFeatureGet(key); + get => FastFeatureGet(key) ?? ConnectionFeatures?[key]; set => FastFeatureSet(key, value); } TFeature IFeatureCollection.Get() { - return (TFeature)FastFeatureGet(typeof(TFeature)); + return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]); } void IFeatureCollection.Set(TFeature instance) diff --git a/src/Kestrel.Core/Internal/Http/Frame.cs b/src/Kestrel.Core/Internal/Http/Frame.cs index 1debda07d0..d8eb4096f8 100644 --- a/src/Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Kestrel.Core/Internal/Http/Frame.cs @@ -83,6 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http private HttpRequestTarget _requestTargetForm = HttpRequestTarget.Unknown; private Uri _absoluteRequestTarget; + private string _scheme = null; public Frame(FrameContext frameContext) { @@ -338,7 +339,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; AllowSynchronousIO = ServerOptions.AllowSynchronousIO; TraceIdentifier = null; - Scheme = null; Method = null; PathBase = null; Path = null; @@ -362,20 +362,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http RequestHeaders = FrameRequestHeaders; ResponseHeaders = FrameResponseHeaders; - if (ConnectionFeatures != null) + if (_scheme == null) { - foreach (var feature in ConnectionFeatures) - { - // Set the scheme to https if there's an ITlsConnectionFeature - if (feature.Key == typeof(ITlsConnectionFeature)) - { - Scheme = "https"; - } - - FastFeatureSet(feature.Key, feature.Value); - } + var tlsFeature = ConnectionFeatures?[typeof(ITlsConnectionFeature)]; + _scheme = tlsFeature != null ? "https" : "http"; } + Scheme = _scheme; + _manuallySetRequestAbortToken = null; _abortedCts = null; diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs index 2adb8074d7..c5df791ce8 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.FeatureCollection.cs @@ -246,13 +246,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 object IFeatureCollection.this[Type key] { - get => FastFeatureGet(key); + get => FastFeatureGet(key) ?? ConnectionFeatures?[key]; set => FastFeatureSet(key, value); } TFeature IFeatureCollection.Get() { - return (TFeature)FastFeatureGet(typeof(TFeature)); + return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]); } void IFeatureCollection.Set(TFeature instance) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs index 0415cb3449..c7b6b4b3ac 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Stream.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Stream.cs @@ -58,6 +58,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 private HttpRequestTarget _requestTargetForm = HttpRequestTarget.Unknown; private Uri _absoluteRequestTarget; + private string _scheme = null; public Http2Stream(Http2StreamContext context) { @@ -248,7 +249,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 MaxRequestBodySize = ServerOptions.Limits.MaxRequestBodySize; AllowSynchronousIO = ServerOptions.AllowSynchronousIO; TraceIdentifier = null; - Scheme = null; Method = null; PathBase = null; Path = null; @@ -271,20 +271,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 RequestHeaders = FrameRequestHeaders; ResponseHeaders = FrameResponseHeaders; - if (ConnectionFeatures != null) + if (_scheme == null) { - foreach (var feature in ConnectionFeatures) - { - // Set the scheme to https if there's an ITlsConnectionFeature - if (feature.Key == typeof(ITlsConnectionFeature)) - { - Scheme = "https"; - } - - FastFeatureSet(feature.Key, feature.Value); - } + var tlsFeature = ConnectionFeatures?[typeof(ITlsConnectionFeature)]; + _scheme = tlsFeature != null ? "https" : "http"; } + Scheme = _scheme; + _manuallySetRequestAbortToken = null; _abortedCts = null;