diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs index b4828a7982..a8e0e92a74 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -6,10 +6,8 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http.Features; -using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.Server.Kestrel.Http @@ -34,6 +32,42 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _featureRevision++; } + private object ExtraFeatureGet(Type key) + { + if (MaybeExtra == null) + { + return null; + } + for (var i = 0; i < MaybeExtra.Count; i++) + { + var kv = MaybeExtra[i]; + if (kv.Key == key) + { + return kv.Value; + } + } + return null; + } + + private void ExtraFeatureSet(Type key, object value) + { + if (MaybeExtra == null) + { + MaybeExtra = new List>(2); + } + + for (var i = 0; i < MaybeExtra.Count; i++) + { + if (MaybeExtra[i].Key == key) + { + MaybeExtra[i] = new KeyValuePair(key, value); + return; + } + } + MaybeExtra.Add(new KeyValuePair(key, value)); + } + + string IHttpRequestFeature.Protocol { get diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs index dca313f9a7..3339bb30a8 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.Generated.cs @@ -172,52 +172,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { return _currentIHttpSendFileFeature; } - return SlowFeatureGet(key); - } - private object SlowFeatureGet(Type key) - { - if (MaybeExtra == null) - { - if ((_featureOverridenFlags & flagIHttpConnectionFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == ITlsConnectionFeatureType) - { - if ((_featureOverridenFlags & flagITlsConnectionFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == IHttpUpgradeFeatureType) - { - if ((_featureOverridenFlags & flagIHttpUpgradeFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == IHttpWebSocketFeatureType) - { - if ((_featureOverridenFlags & flagIHttpWebSocketFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - if (key == ISessionFeatureType) - { - if ((_featureOverridenFlags & flagISessionFeature) == 0L) - { - return this; - } - return SlowFeatureGet(key); - } - return SlowFeatureGet(key); + return ExtraFeatureGet(key); } @@ -333,7 +289,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _currentIHttpSendFileFeature = feature; return; }; - SetExtra(key, feature); + ExtraFeatureSet(key, feature); } private IEnumerable> FastEnumerable() diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs index 4c45f6802d..8e1cba3a5f 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs @@ -79,35 +79,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {{ return _current{feature.Name}; }}")} - return SlowFeatureGet(key); + + return ExtraFeatureGet(key); }} - private object SlowFeatureGet(Type key) - {{ - object feature = null; - if (MaybeExtra?.TryGetValue(key, out feature) ?? false) - {{ - return feature; - }} - return null; - }} - - private void FastFeatureSetInner(long flag, Type key, object feature) - {{ - Extra[key] = feature; - - // Altering only an individual bit of the long - // so need to make sure other concurrent bit changes are not overridden - // in an atomic yet lock-free manner - - long currentFeatureFlags; - long updatedFeatureFlags; - do - {{ - currentFeatureFlags = _featureOverridenFlags; - updatedFeatureFlags = currentFeatureFlags | flag; - }} while (System.Threading.Interlocked.CompareExchange(ref _featureOverridenFlags, updatedFeatureFlags, currentFeatureFlags) != currentFeatureFlags); - private void FastFeatureSet(Type key, object feature) {{ _featureRevision++; @@ -117,7 +92,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http _current{feature.Name} = feature; return; }}")}; - SetExtra(key, feature); + ExtraFeatureSet(key, feature); }} private IEnumerable> FastEnumerable()