This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 523
Frame implementing mutable IFeatureCollection #243
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dcf591c
Rough implementation of feature collection optimization
lodejard d48a27d
Use bitflag for override and cache typeof in statics
benaadams 05702e8
more typeof caching
benaadams e107c47
Add comment explanation
benaadams 4797354
Remove redundant cast
benaadams 6b0fa77
More comment clarity
benaadams 71fc2bf
Rough implementation of feature collection optimization
lodejard dc0eb67
Updating unit tests for Frame IFeatureCollection update
lodejard cbc3b4e
PR Feedback
lodejard 56893df
Don't iterate overriden features twice
benaadams 3c20053
Don used cached typeof for tests
benaadams 8f41e47
Remove bitfield for locally implemented interface items
benaadams ccfeef6
All features to have backing object
benaadams 29b0b12
Moving non-changing methods into .cs partial
lodejard 6ae0f5d
PR feedback - code formatting
lodejard daf2721
Visual Studio insists NuGet.config MUST have a BOM
lodejard 78177e7
Fixing rebase errors
lodejard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
285 changes: 285 additions & 0 deletions
285
src/Microsoft.AspNet.Server.Kestrel/Http/Frame.FeatureCollection.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
// 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; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Http.Features; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace Microsoft.AspNet.Server.Kestrel.Http | ||
{ | ||
public partial class Frame : IFeatureCollection, IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature | ||
{ | ||
// NOTE: When feature interfaces are added to or removed from this Frame class implementation, | ||
// then the list of `implementedFeatures` in the generated code project MUST also be updated. | ||
// See also: tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/FrameFeatureCollection.cs | ||
|
||
private string _scheme; | ||
private string _pathBase; | ||
private int _featureRevision; | ||
|
||
private List<KeyValuePair<Type, object>> MaybeExtra; | ||
|
||
public void ResetFeatureCollection() | ||
{ | ||
FastReset(); | ||
MaybeExtra?.Clear(); | ||
_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<KeyValuePair<Type, object>>(2); | ||
} | ||
|
||
for (var i = 0; i < MaybeExtra.Count; i++) | ||
{ | ||
if (MaybeExtra[i].Key == key) | ||
{ | ||
MaybeExtra[i] = new KeyValuePair<Type, object>(key, value); | ||
return; | ||
} | ||
} | ||
MaybeExtra.Add(new KeyValuePair<Type, object>(key, value)); | ||
} | ||
|
||
|
||
string IHttpRequestFeature.Protocol | ||
{ | ||
get | ||
{ | ||
return HttpVersion; | ||
} | ||
|
||
set | ||
{ | ||
HttpVersion = value; | ||
} | ||
} | ||
|
||
string IHttpRequestFeature.Scheme | ||
{ | ||
get | ||
{ | ||
return _scheme ?? "http"; | ||
} | ||
|
||
set | ||
{ | ||
_scheme = value; | ||
} | ||
} | ||
|
||
string IHttpRequestFeature.Method | ||
{ | ||
get | ||
{ | ||
return Method; | ||
} | ||
|
||
set | ||
{ | ||
Method = value; | ||
} | ||
} | ||
|
||
string IHttpRequestFeature.PathBase | ||
{ | ||
get | ||
{ | ||
return _pathBase ?? ""; | ||
} | ||
|
||
set | ||
{ | ||
_pathBase = value; | ||
} | ||
} | ||
|
||
string IHttpRequestFeature.Path | ||
{ | ||
get | ||
{ | ||
return Path; | ||
} | ||
|
||
set | ||
{ | ||
Path = value; | ||
} | ||
} | ||
|
||
string IHttpRequestFeature.QueryString | ||
{ | ||
get | ||
{ | ||
return QueryString; | ||
} | ||
|
||
set | ||
{ | ||
QueryString = value; | ||
} | ||
} | ||
|
||
IDictionary<string, StringValues> IHttpRequestFeature.Headers | ||
{ | ||
get | ||
{ | ||
return RequestHeaders; | ||
} | ||
|
||
set | ||
{ | ||
RequestHeaders = value; | ||
} | ||
} | ||
|
||
Stream IHttpRequestFeature.Body | ||
{ | ||
get | ||
{ | ||
return RequestBody; | ||
} | ||
|
||
set | ||
{ | ||
RequestBody = value; | ||
} | ||
} | ||
|
||
int IHttpResponseFeature.StatusCode | ||
{ | ||
get | ||
{ | ||
return StatusCode; | ||
} | ||
|
||
set | ||
{ | ||
StatusCode = value; | ||
} | ||
} | ||
|
||
string IHttpResponseFeature.ReasonPhrase | ||
{ | ||
get | ||
{ | ||
return ReasonPhrase; | ||
} | ||
|
||
set | ||
{ | ||
ReasonPhrase = value; | ||
} | ||
} | ||
|
||
IDictionary<string, StringValues> IHttpResponseFeature.Headers | ||
{ | ||
get | ||
{ | ||
return ResponseHeaders; | ||
} | ||
|
||
set | ||
{ | ||
ResponseHeaders = value; | ||
} | ||
} | ||
|
||
Stream IHttpResponseFeature.Body | ||
{ | ||
get | ||
{ | ||
return ResponseBody; | ||
} | ||
|
||
set | ||
{ | ||
ResponseBody = value; | ||
} | ||
} | ||
|
||
bool IHttpResponseFeature.HasStarted | ||
{ | ||
get { return HasResponseStarted; } | ||
} | ||
|
||
bool IHttpUpgradeFeature.IsUpgradableRequest | ||
{ | ||
get | ||
{ | ||
StringValues values; | ||
if (RequestHeaders.TryGetValue("Connection", out values)) | ||
{ | ||
return values.Any(value => value.IndexOf("upgrade", StringComparison.OrdinalIgnoreCase) != -1); | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
bool IFeatureCollection.IsReadOnly => false; | ||
|
||
int IFeatureCollection.Revision => _featureRevision; | ||
|
||
object IFeatureCollection.this[Type key] | ||
{ | ||
get { return FastFeatureGet(key); } | ||
set { FastFeatureSet(key, value); } | ||
} | ||
|
||
void IHttpResponseFeature.OnStarting(Func<object, Task> callback, object state) | ||
{ | ||
OnStarting(callback, state); | ||
} | ||
|
||
void IHttpResponseFeature.OnCompleted(Func<object, Task> callback, object state) | ||
{ | ||
OnCompleted(callback, state); | ||
} | ||
|
||
Task<Stream> IHttpUpgradeFeature.UpgradeAsync() | ||
{ | ||
StatusCode = 101; | ||
ReasonPhrase = "Switching Protocols"; | ||
ResponseHeaders["Connection"] = "Upgrade"; | ||
if (!ResponseHeaders.ContainsKey("Upgrade")) | ||
{ | ||
StringValues values; | ||
if (RequestHeaders.TryGetValue("Upgrade", out values)) | ||
{ | ||
ResponseHeaders["Upgrade"] = values; | ||
} | ||
} | ||
ProduceStart(); | ||
return Task.FromResult(DuplexStream); | ||
} | ||
|
||
IEnumerator<KeyValuePair<Type, object>> IEnumerable<KeyValuePair<Type, object>>.GetEnumerator() => FastEnumerable().GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => FastEnumerable().GetEnumerator(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆗