All features to have backing object

This commit is contained in:
Ben Adams 2015-10-08 14:42:57 -04:00 committed by Louis DeJardin
parent 8f41e47eca
commit ccfeef6353
2 changed files with 103 additions and 9 deletions

View File

@ -24,6 +24,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature);
private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature);
private static readonly Type IHttpUpgradeFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature);
private static readonly Type IResponseCookiesFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature);
private static readonly Type IItemsFeatureType = typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature);
private static readonly Type ITlsConnectionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature);
private static readonly Type IHttpWebSocketFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature);
private static readonly Type ISessionFeatureType = typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature);
private static readonly Type IHttpSendFileFeatureType = typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature);
private object _currentIHttpRequestFeature;
private object _currentIHttpResponseFeature;
@ -35,6 +41,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private object _currentIQueryFeature;
private object _currentIFormFeature;
private object _currentIHttpUpgradeFeature;
private object _currentIResponseCookiesFeature;
private object _currentIItemsFeature;
private object _currentITlsConnectionFeature;
private object _currentIHttpWebSocketFeature;
private object _currentISessionFeature;
private object _currentIHttpSendFileFeature;
private void FastReset()
{
@ -49,6 +61,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
_currentIHttpAuthenticationFeature = null;
_currentIQueryFeature = null;
_currentIFormFeature = null;
_currentIResponseCookiesFeature = null;
_currentIItemsFeature = null;
_currentITlsConnectionFeature = null;
_currentIHttpWebSocketFeature = null;
_currentISessionFeature = null;
_currentIHttpSendFileFeature = null;
}
private object FastFeatureGet(Type key)
@ -130,6 +148,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
return _currentIHttpUpgradeFeature;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature))
{
return _currentIResponseCookiesFeature;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature))
{
return _currentIItemsFeature;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature))
{
return _currentITlsConnectionFeature;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature))
{
return _currentIHttpWebSocketFeature;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature))
{
return _currentISessionFeature;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature))
{
return _currentIHttpSendFileFeature;
}
return SlowFeatureGet(key);
}
@ -260,6 +302,36 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
_currentIHttpUpgradeFeature = feature;
return;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature))
{
_currentIResponseCookiesFeature = feature;
return;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature))
{
_currentIItemsFeature = feature;
return;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature))
{
_currentITlsConnectionFeature = feature;
return;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature))
{
_currentIHttpWebSocketFeature = feature;
return;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.ISessionFeature))
{
_currentISessionFeature = feature;
return;
}
if (key == typeof(global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature))
{
_currentIHttpSendFileFeature = feature;
return;
};
SetExtra(key, feature);
}
@ -330,6 +402,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
yield return new KeyValuePair<Type, object>(IHttpUpgradeFeatureType, _currentIHttpUpgradeFeature as global::Microsoft.AspNet.Http.Features.IHttpUpgradeFeature);
}
if (_currentIResponseCookiesFeature != null)
{
yield return new KeyValuePair<Type, object>(IResponseCookiesFeatureType, _currentIResponseCookiesFeature as global::Microsoft.AspNet.Http.Features.Internal.IResponseCookiesFeature);
}
if (_currentIItemsFeature != null)
{
yield return new KeyValuePair<Type, object>(IItemsFeatureType, _currentIItemsFeature as global::Microsoft.AspNet.Http.Features.Internal.IItemsFeature);
}
if (_currentITlsConnectionFeature != null)
{
yield return new KeyValuePair<Type, object>(ITlsConnectionFeatureType, _currentITlsConnectionFeature as global::Microsoft.AspNet.Http.Features.ITlsConnectionFeature);
}
if (_currentIHttpWebSocketFeature != null)
{
yield return new KeyValuePair<Type, object>(IHttpWebSocketFeatureType, _currentIHttpWebSocketFeature as global::Microsoft.AspNet.Http.Features.IHttpWebSocketFeature);
}
if (_currentISessionFeature != null)
{
yield return new KeyValuePair<Type, object>(ISessionFeatureType, _currentISessionFeature as global::Microsoft.AspNet.Http.Features.ISessionFeature);
}
if (_currentIHttpSendFileFeature != null)
{
yield return new KeyValuePair<Type, object>(IHttpSendFileFeatureType, _currentIHttpSendFileFeature as global::Microsoft.AspNet.Http.Features.IHttpSendFileFeature);
}
if (MaybeExtra != null)
{

View File

@ -53,10 +53,6 @@ namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode
typeof(IHttpResponseFeature),
typeof(IHttpUpgradeFeature),
};
// Only the always, common and implmented features will have backed objects
// the sometimes, rare and user-defined features will use the MaybeExtra collection
var cachedFeatures = alwaysFeatures.Concat(commonFeatures).Union(implementedFeatures);
return $@"
using System;
@ -65,18 +61,20 @@ using System.Collections.Generic;
namespace Microsoft.AspNet.Server.Kestrel.Http
{{
public partial class Frame
{{{Each(cachedFeatures, feature => $@"
{{{Each(allFeatures, feature => $@"
private static readonly Type {feature.Name}Type = typeof(global::{feature.FullName});")}
{Each(allFeatures, feature => $@"
private object _current{feature.Name};")}
private void FastReset()
{{{Each(implementedFeatures, feature => $@"
_current{feature.Name} = this;")}
{Each(cachedFeatures.Where( f => !implementedFeatures.Contains(f)), feature => $@"
{Each(allFeatures.Where( f => !implementedFeatures.Contains(f)), feature => $@"
_current{feature.Name} = null;")}
}}
private object FastFeatureGet(Type key)
{{{Each(cachedFeatures, feature => $@"
{{{Each(allFeatures, feature => $@"
if (key == typeof(global::{feature.FullName}))
{{
return _current{feature.Name};
@ -113,7 +111,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private void FastFeatureSet(Type key, object feature)
{{
_featureRevision++;
{Each(cachedFeatures, feature => $@"
{Each(allFeatures, feature => $@"
if (key == typeof(global::{feature.FullName}))
{{
_current{feature.Name} = feature;
@ -123,7 +121,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
}}
private IEnumerable<KeyValuePair<Type, object>> FastEnumerable()
{{{Each(cachedFeatures, feature => $@"
{{{Each(allFeatures, feature => $@"
if (_current{feature.Name} != null)
{{
yield return new KeyValuePair<Type, object>({feature.Name}Type, _current{feature.Name} as global::{feature.FullName});