Don't alloc IEnumerable in Reset for ITlsConnectionFeature (#2009)

* Don't alloc IEnumerable for ITlsConnectionFeature
* Delegate to ConnectionFeatures and determine scheme once
This commit is contained in:
Ben Adams 2017-08-22 01:01:05 +01:00 committed by Stephen Halter
parent 2e6687031d
commit 11a9b6498d
4 changed files with 16 additions and 28 deletions

View File

@ -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<TFeature>()
{
return (TFeature)FastFeatureGet(typeof(TFeature));
return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]);
}
void IFeatureCollection.Set<TFeature>(TFeature instance)

View File

@ -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;

View File

@ -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<TFeature>()
{
return (TFeature)FastFeatureGet(typeof(TFeature));
return (TFeature)(FastFeatureGet(typeof(TFeature)) ?? ConnectionFeatures?[typeof(TFeature)]);
}
void IFeatureCollection.Set<TFeature>(TFeature instance)

View File

@ -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;