diff --git a/src/Microsoft.AspNet.Server.WebListener/OwinServerFactory.cs b/src/Microsoft.AspNet.Server.WebListener/OwinServerFactory.cs index 6b0b205db7..fa90780375 100644 --- a/src/Microsoft.AspNet.Server.WebListener/OwinServerFactory.cs +++ b/src/Microsoft.AspNet.Server.WebListener/OwinServerFactory.cs @@ -26,7 +26,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.WebListener { - using AppFunc = Func, Task>; + using AppFunc = Func; using LoggerFactoryFunc = Func, bool>>; /// diff --git a/src/Microsoft.AspNet.Server.WebListener/OwinWebListener.cs b/src/Microsoft.AspNet.Server.WebListener/OwinWebListener.cs index d6c1cd916a..5f7b8c3ffb 100644 --- a/src/Microsoft.AspNet.Server.WebListener/OwinWebListener.cs +++ b/src/Microsoft.AspNet.Server.WebListener/OwinWebListener.cs @@ -18,7 +18,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Server.WebListener { - using AppFunc = Func, Task>; + using AppFunc = Func; using LoggerFactoryFunc = Func, bool>>; using LoggerFunc = Func, bool>; @@ -518,7 +518,7 @@ namespace Microsoft.AspNet.Server.WebListener { // TODO: Make disconnect registration lazy RegisterForDisconnectNotification(requestContext); - await _appFunc(requestContext.Environment).SupressContext(); + await _appFunc(requestContext.Features).SupressContext(); await requestContext.ProcessResponseAsync().SupressContext(); } catch (Exception ex) @@ -832,7 +832,8 @@ namespace Microsoft.AspNet.Server.WebListener ulong connectionId = requestContext.Request.ConnectionId; CancellationToken ct = GetConnectionCancellation(connectionId); requestContext.Request.RegisterForDisconnect(ct); - requestContext.Environment.ConnectionDisconnect = ct; + // TODO: Need a feature equivalent for owin.CallCancelled. + // requestContext.Environment.ConnectionDisconnect = ct; } catch (Win32Exception exception) { diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.Generated.cs b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.Generated.cs deleted file mode 100644 index d0fe8d05ea..0000000000 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.Generated.cs +++ /dev/null @@ -1,1913 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (c) Katana Contributors. All rights reserved. -// -//----------------------------------------------------------------------- -// - -using System; -using System.CodeDom.Compiler; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Security.Authentication.ExtendedProtection; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Server.WebListener -{ - using OpaqueUpgrade = Action, Func, Task>>; - - [GeneratedCode("TextTemplatingFileGenerator", "")] - internal partial class CallEnvironment - { - // Mark all fields with delay initialization support as set. - private UInt32 _flag0 = 0x43e00200u; - private UInt32 _flag1 = 0x1u; - // Mark all fields with delay initialization support as requiring initialization. - private UInt32 _initFlag0 = 0x43e00200u; - private UInt32 _initFlag1 = 0x1u; - - internal interface IPropertySource - { - Stream GetRequestBody(); - string GetRemoteIpAddress(); - string GetRemotePort(); - string GetLocalIpAddress(); - string GetLocalPort(); - bool GetIsLocal(); - bool TryGetChannelBinding(ref ChannelBinding value); - bool TryGetOpaqueUpgrade(ref OpaqueUpgrade value); - } - - private string _OwinVersion; - private CancellationToken _CallCancelled; - private string _RequestProtocol; - private string _RequestMethod; - private string _RequestScheme; - private string _RequestPathBase; - private string _RequestPath; - private string _RequestQueryString; - private IDictionary _RequestHeaders; - private Stream _RequestBody; - private IDictionary _ResponseHeaders; - private Stream _ResponseBody; - private int? _ResponseStatusCode; - private string _ResponseReasonPhrase; - private TextWriter _HostTraceOutput; - private string _HostAppName; - private string _HostAppMode; - private CancellationToken _OnAppDisposing; - private System.Security.Principal.IPrincipal _User; - private Action, object> _OnSendingHeaders; - private IDictionary _ServerCapabilities; - private string _RemoteIpAddress; - private string _RemotePort; - private string _LocalIpAddress; - private string _LocalPort; - private bool _IsLocal; - private object _ConnectionId; - private CancellationToken _ConnectionDisconnect; - private object _ClientCert; - private Func _LoadClientCert; - private ChannelBinding _ChannelBinding; - private Func _SendFileAsync; - private OpaqueUpgrade _OpaqueUpgrade; - private OwinWebListener _Listener; - - bool InitPropertyChannelBinding() - { - if (!_propertySource.TryGetChannelBinding(ref _ChannelBinding)) - { - _flag0 &= ~0x40000000u; - _initFlag0 &= ~0x40000000u; - return false; - } - _initFlag0 &= ~0x40000000u; - return true; - } - - bool InitPropertyOpaqueUpgrade() - { - if (!_propertySource.TryGetOpaqueUpgrade(ref _OpaqueUpgrade)) - { - _flag1 &= ~0x1u; - _initFlag1 &= ~0x1u; - return false; - } - _initFlag1 &= ~0x1u; - return true; - } - - internal string OwinVersion - { - get - { - return _OwinVersion; - } - set - { - _flag0 |= 0x1u; - _OwinVersion = value; - } - } - - internal CancellationToken CallCancelled - { - get - { - return _CallCancelled; - } - set - { - _flag0 |= 0x2u; - _CallCancelled = value; - } - } - - internal string RequestProtocol - { - get - { - return _RequestProtocol; - } - set - { - _flag0 |= 0x4u; - _RequestProtocol = value; - } - } - - internal string RequestMethod - { - get - { - return _RequestMethod; - } - set - { - _flag0 |= 0x8u; - _RequestMethod = value; - } - } - - internal string RequestScheme - { - get - { - return _RequestScheme; - } - set - { - _flag0 |= 0x10u; - _RequestScheme = value; - } - } - - internal string RequestPathBase - { - get - { - return _RequestPathBase; - } - set - { - _flag0 |= 0x20u; - _RequestPathBase = value; - } - } - - internal string RequestPath - { - get - { - return _RequestPath; - } - set - { - _flag0 |= 0x40u; - _RequestPath = value; - } - } - - internal string RequestQueryString - { - get - { - return _RequestQueryString; - } - set - { - _flag0 |= 0x80u; - _RequestQueryString = value; - } - } - - internal IDictionary RequestHeaders - { - get - { - return _RequestHeaders; - } - set - { - _flag0 |= 0x100u; - _RequestHeaders = value; - } - } - - internal Stream RequestBody - { - get - { - if (((_initFlag0 & 0x200u) != 0)) - { - _RequestBody = _propertySource.GetRequestBody(); - _initFlag0 &= ~0x200u; - } - return _RequestBody; - } - set - { - _initFlag0 &= ~0x200u; - _flag0 |= 0x200u; - _RequestBody = value; - } - } - - internal IDictionary ResponseHeaders - { - get - { - return _ResponseHeaders; - } - set - { - _flag0 |= 0x400u; - _ResponseHeaders = value; - } - } - - internal Stream ResponseBody - { - get - { - return _ResponseBody; - } - set - { - _flag0 |= 0x800u; - _ResponseBody = value; - } - } - - internal int? ResponseStatusCode - { - get - { - return _ResponseStatusCode; - } - set - { - _flag0 |= 0x1000u; - _ResponseStatusCode = value; - } - } - - internal string ResponseReasonPhrase - { - get - { - return _ResponseReasonPhrase; - } - set - { - _flag0 |= 0x2000u; - _ResponseReasonPhrase = value; - } - } - - internal TextWriter HostTraceOutput - { - get - { - return _HostTraceOutput; - } - set - { - _flag0 |= 0x4000u; - _HostTraceOutput = value; - } - } - - internal string HostAppName - { - get - { - return _HostAppName; - } - set - { - _flag0 |= 0x8000u; - _HostAppName = value; - } - } - - internal string HostAppMode - { - get - { - return _HostAppMode; - } - set - { - _flag0 |= 0x10000u; - _HostAppMode = value; - } - } - - internal CancellationToken OnAppDisposing - { - get - { - return _OnAppDisposing; - } - set - { - _flag0 |= 0x20000u; - _OnAppDisposing = value; - } - } - - internal System.Security.Principal.IPrincipal User - { - get - { - return _User; - } - set - { - _flag0 |= 0x40000u; - _User = value; - } - } - - internal Action, object> OnSendingHeaders - { - get - { - return _OnSendingHeaders; - } - set - { - _flag0 |= 0x80000u; - _OnSendingHeaders = value; - } - } - - internal IDictionary ServerCapabilities - { - get - { - return _ServerCapabilities; - } - set - { - _flag0 |= 0x100000u; - _ServerCapabilities = value; - } - } - - internal string RemoteIpAddress - { - get - { - if (((_initFlag0 & 0x200000u) != 0)) - { - _RemoteIpAddress = _propertySource.GetRemoteIpAddress(); - _initFlag0 &= ~0x200000u; - } - return _RemoteIpAddress; - } - set - { - _initFlag0 &= ~0x200000u; - _flag0 |= 0x200000u; - _RemoteIpAddress = value; - } - } - - internal string RemotePort - { - get - { - if (((_initFlag0 & 0x400000u) != 0)) - { - _RemotePort = _propertySource.GetRemotePort(); - _initFlag0 &= ~0x400000u; - } - return _RemotePort; - } - set - { - _initFlag0 &= ~0x400000u; - _flag0 |= 0x400000u; - _RemotePort = value; - } - } - - internal string LocalIpAddress - { - get - { - if (((_initFlag0 & 0x800000u) != 0)) - { - _LocalIpAddress = _propertySource.GetLocalIpAddress(); - _initFlag0 &= ~0x800000u; - } - return _LocalIpAddress; - } - set - { - _initFlag0 &= ~0x800000u; - _flag0 |= 0x800000u; - _LocalIpAddress = value; - } - } - - internal string LocalPort - { - get - { - if (((_initFlag0 & 0x1000000u) != 0)) - { - _LocalPort = _propertySource.GetLocalPort(); - _initFlag0 &= ~0x1000000u; - } - return _LocalPort; - } - set - { - _initFlag0 &= ~0x1000000u; - _flag0 |= 0x1000000u; - _LocalPort = value; - } - } - - internal bool IsLocal - { - get - { - if (((_initFlag0 & 0x2000000u) != 0)) - { - _IsLocal = _propertySource.GetIsLocal(); - _initFlag0 &= ~0x2000000u; - } - return _IsLocal; - } - set - { - _initFlag0 &= ~0x2000000u; - _flag0 |= 0x2000000u; - _IsLocal = value; - } - } - - internal object ConnectionId - { - get - { - return _ConnectionId; - } - set - { - _flag0 |= 0x4000000u; - _ConnectionId = value; - } - } - - internal CancellationToken ConnectionDisconnect - { - get - { - return _ConnectionDisconnect; - } - set - { - _flag0 |= 0x8000000u; - _ConnectionDisconnect = value; - } - } - - internal object ClientCert - { - get - { - return _ClientCert; - } - set - { - _flag0 |= 0x10000000u; - _ClientCert = value; - } - } - - internal Func LoadClientCert - { - get - { - return _LoadClientCert; - } - set - { - _flag0 |= 0x20000000u; - _LoadClientCert = value; - } - } - - internal ChannelBinding ChannelBinding - { - get - { - if (((_initFlag0 & 0x40000000u) != 0)) - { - InitPropertyChannelBinding(); - } - return _ChannelBinding; - } - set - { - _initFlag0 &= ~0x40000000u; - _flag0 |= 0x40000000u; - _ChannelBinding = value; - } - } - - internal Func SendFileAsync - { - get - { - return _SendFileAsync; - } - set - { - _flag0 |= 0x80000000u; - _SendFileAsync = value; - } - } - - internal OpaqueUpgrade OpaqueUpgrade - { - get - { - if (((_initFlag1 & 0x1u) != 0)) - { - InitPropertyOpaqueUpgrade(); - } - return _OpaqueUpgrade; - } - set - { - _initFlag1 &= ~0x1u; - _flag1 |= 0x1u; - _OpaqueUpgrade = value; - } - } - - internal OwinWebListener Listener - { - get - { - return _Listener; - } - set - { - _flag1 |= 0x2u; - _Listener = value; - } - } - - private bool PropertiesContainsKey(string key) - { - switch (key.Length) - { - case 11: - if (((_flag0 & 0x40000u) != 0) && string.Equals(key, "server.User", StringComparison.Ordinal)) - { - return true; - } - break; - case 12: - if (((_flag0 & 0x1u) != 0) && string.Equals(key, "owin.Version", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x8000u) != 0) && string.Equals(key, "host.AppName", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x10000u) != 0) && string.Equals(key, "host.AppMode", StringComparison.Ordinal)) - { - return true; - } - break; - case 14: - if (((_flag0 & 0x2000000u) != 0) && string.Equals(key, "server.IsLocal", StringComparison.Ordinal)) - { - return true; - } - if (((_flag1 & 0x1u) != 0) && string.Equals(key, "opaque.Upgrade", StringComparison.Ordinal)) - { - if (((_initFlag1 & 0x1u) == 0) || InitPropertyOpaqueUpgrade()) - { - return true; - } - } - break; - case 16: - if (((_flag0 & 0x40u) != 0) && string.Equals(key, "owin.RequestPath", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x200u) != 0) && string.Equals(key, "owin.RequestBody", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x4000u) != 0) && string.Equals(key, "host.TraceOutput", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x1000000u) != 0) && string.Equals(key, "server.LocalPort", StringComparison.Ordinal)) - { - return true; - } - break; - case 17: - if (((_flag0 & 0x800u) != 0) && string.Equals(key, "owin.ResponseBody", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x400000u) != 0) && string.Equals(key, "server.RemotePort", StringComparison.Ordinal)) - { - return true; - } - break; - case 18: - if (((_flag0 & 0x2u) != 0) && string.Equals(key, "owin.CallCancelled", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x8u) != 0) && string.Equals(key, "owin.RequestMethod", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x10u) != 0) && string.Equals(key, "owin.RequestScheme", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x40000000u) != 0) && string.Equals(key, "ssl.ChannelBinding", StringComparison.Ordinal)) - { - if (((_initFlag0 & 0x40000000u) == 0) || InitPropertyChannelBinding()) - { - return true; - } - } - if (((_flag0 & 0x80000000u) != 0) && string.Equals(key, "sendfile.SendAsync", StringComparison.Ordinal)) - { - return true; - } - break; - case 19: - if (((_flag0 & 0x100u) != 0) && string.Equals(key, "owin.RequestHeaders", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x20000u) != 0) && string.Equals(key, "host.OnAppDisposing", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x100000u) != 0) && string.Equals(key, "server.Capabilities", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x4000000u) != 0) && string.Equals(key, "server.ConnectionId", StringComparison.Ordinal)) - { - return true; - } - break; - case 20: - if (((_flag0 & 0x4u) != 0) && string.Equals(key, "owin.RequestProtocol", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x20u) != 0) && string.Equals(key, "owin.RequestPathBase", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x400u) != 0) && string.Equals(key, "owin.ResponseHeaders", StringComparison.Ordinal)) - { - return true; - } - break; - case 21: - if (((_flag0 & 0x800000u) != 0) && string.Equals(key, "server.LocalIpAddress", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x10000000u) != 0) && string.Equals(key, "ssl.ClientCertificate", StringComparison.Ordinal)) - { - return true; - } - break; - case 22: - if (((_flag0 & 0x200000u) != 0) && string.Equals(key, "server.RemoteIpAddress", StringComparison.Ordinal)) - { - return true; - } - break; - case 23: - if (((_flag0 & 0x80u) != 0) && string.Equals(key, "owin.RequestQueryString", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x1000u) != 0) && string.Equals(key, "owin.ResponseStatusCode", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x80000u) != 0) && string.Equals(key, "server.OnSendingHeaders", StringComparison.Ordinal)) - { - return true; - } - if (((_flag0 & 0x20000000u) != 0) && string.Equals(key, "ssl.LoadClientCertAsync", StringComparison.Ordinal)) - { - return true; - } - break; - case 25: - if (((_flag0 & 0x2000u) != 0) && string.Equals(key, "owin.ResponseReasonPhrase", StringComparison.Ordinal)) - { - return true; - } - break; - case 27: - if (((_flag0 & 0x8000000u) != 0) && string.Equals(key, "server.ConnectionDisconnect", StringComparison.Ordinal)) - { - return true; - } - break; - case 51: - if (((_flag1 & 0x2u) != 0) && string.Equals(key, "Microsoft.AspNet.Server.WebListener.OwinWebListener", StringComparison.Ordinal)) - { - return true; - } - break; - } - return false; - } - - private bool PropertiesTryGetValue(string key, out object value) - { - switch (key.Length) - { - case 11: - if (((_flag0 & 0x40000u) != 0) && string.Equals(key, "server.User", StringComparison.Ordinal)) - { - value = User; - return true; - } - break; - case 12: - if (((_flag0 & 0x1u) != 0) && string.Equals(key, "owin.Version", StringComparison.Ordinal)) - { - value = OwinVersion; - return true; - } - if (((_flag0 & 0x8000u) != 0) && string.Equals(key, "host.AppName", StringComparison.Ordinal)) - { - value = HostAppName; - return true; - } - if (((_flag0 & 0x10000u) != 0) && string.Equals(key, "host.AppMode", StringComparison.Ordinal)) - { - value = HostAppMode; - return true; - } - break; - case 14: - if (((_flag0 & 0x2000000u) != 0) && string.Equals(key, "server.IsLocal", StringComparison.Ordinal)) - { - value = IsLocal; - return true; - } - if (((_flag1 & 0x1u) != 0) && string.Equals(key, "opaque.Upgrade", StringComparison.Ordinal)) - { - value = OpaqueUpgrade; - // Delayed initialization in the property getter may determine that the element is not actually present - if (!((_flag1 & 0x1u) != 0)) - { - value = default(OpaqueUpgrade); - return false; - } - return true; - } - break; - case 16: - if (((_flag0 & 0x40u) != 0) && string.Equals(key, "owin.RequestPath", StringComparison.Ordinal)) - { - value = RequestPath; - return true; - } - if (((_flag0 & 0x200u) != 0) && string.Equals(key, "owin.RequestBody", StringComparison.Ordinal)) - { - value = RequestBody; - return true; - } - if (((_flag0 & 0x4000u) != 0) && string.Equals(key, "host.TraceOutput", StringComparison.Ordinal)) - { - value = HostTraceOutput; - return true; - } - if (((_flag0 & 0x1000000u) != 0) && string.Equals(key, "server.LocalPort", StringComparison.Ordinal)) - { - value = LocalPort; - return true; - } - break; - case 17: - if (((_flag0 & 0x800u) != 0) && string.Equals(key, "owin.ResponseBody", StringComparison.Ordinal)) - { - value = ResponseBody; - return true; - } - if (((_flag0 & 0x400000u) != 0) && string.Equals(key, "server.RemotePort", StringComparison.Ordinal)) - { - value = RemotePort; - return true; - } - break; - case 18: - if (((_flag0 & 0x2u) != 0) && string.Equals(key, "owin.CallCancelled", StringComparison.Ordinal)) - { - value = CallCancelled; - return true; - } - if (((_flag0 & 0x8u) != 0) && string.Equals(key, "owin.RequestMethod", StringComparison.Ordinal)) - { - value = RequestMethod; - return true; - } - if (((_flag0 & 0x10u) != 0) && string.Equals(key, "owin.RequestScheme", StringComparison.Ordinal)) - { - value = RequestScheme; - return true; - } - if (((_flag0 & 0x40000000u) != 0) && string.Equals(key, "ssl.ChannelBinding", StringComparison.Ordinal)) - { - value = ChannelBinding; - // Delayed initialization in the property getter may determine that the element is not actually present - if (!((_flag0 & 0x40000000u) != 0)) - { - value = default(ChannelBinding); - return false; - } - return true; - } - if (((_flag0 & 0x80000000u) != 0) && string.Equals(key, "sendfile.SendAsync", StringComparison.Ordinal)) - { - value = SendFileAsync; - return true; - } - break; - case 19: - if (((_flag0 & 0x100u) != 0) && string.Equals(key, "owin.RequestHeaders", StringComparison.Ordinal)) - { - value = RequestHeaders; - return true; - } - if (((_flag0 & 0x20000u) != 0) && string.Equals(key, "host.OnAppDisposing", StringComparison.Ordinal)) - { - value = OnAppDisposing; - return true; - } - if (((_flag0 & 0x100000u) != 0) && string.Equals(key, "server.Capabilities", StringComparison.Ordinal)) - { - value = ServerCapabilities; - return true; - } - if (((_flag0 & 0x4000000u) != 0) && string.Equals(key, "server.ConnectionId", StringComparison.Ordinal)) - { - value = ConnectionId; - return true; - } - break; - case 20: - if (((_flag0 & 0x4u) != 0) && string.Equals(key, "owin.RequestProtocol", StringComparison.Ordinal)) - { - value = RequestProtocol; - return true; - } - if (((_flag0 & 0x20u) != 0) && string.Equals(key, "owin.RequestPathBase", StringComparison.Ordinal)) - { - value = RequestPathBase; - return true; - } - if (((_flag0 & 0x400u) != 0) && string.Equals(key, "owin.ResponseHeaders", StringComparison.Ordinal)) - { - value = ResponseHeaders; - return true; - } - break; - case 21: - if (((_flag0 & 0x800000u) != 0) && string.Equals(key, "server.LocalIpAddress", StringComparison.Ordinal)) - { - value = LocalIpAddress; - return true; - } - if (((_flag0 & 0x10000000u) != 0) && string.Equals(key, "ssl.ClientCertificate", StringComparison.Ordinal)) - { - value = ClientCert; - return true; - } - break; - case 22: - if (((_flag0 & 0x200000u) != 0) && string.Equals(key, "server.RemoteIpAddress", StringComparison.Ordinal)) - { - value = RemoteIpAddress; - return true; - } - break; - case 23: - if (((_flag0 & 0x80u) != 0) && string.Equals(key, "owin.RequestQueryString", StringComparison.Ordinal)) - { - value = RequestQueryString; - return true; - } - if (((_flag0 & 0x1000u) != 0) && string.Equals(key, "owin.ResponseStatusCode", StringComparison.Ordinal)) - { - value = ResponseStatusCode; - return true; - } - if (((_flag0 & 0x80000u) != 0) && string.Equals(key, "server.OnSendingHeaders", StringComparison.Ordinal)) - { - value = OnSendingHeaders; - return true; - } - if (((_flag0 & 0x20000000u) != 0) && string.Equals(key, "ssl.LoadClientCertAsync", StringComparison.Ordinal)) - { - value = LoadClientCert; - return true; - } - break; - case 25: - if (((_flag0 & 0x2000u) != 0) && string.Equals(key, "owin.ResponseReasonPhrase", StringComparison.Ordinal)) - { - value = ResponseReasonPhrase; - return true; - } - break; - case 27: - if (((_flag0 & 0x8000000u) != 0) && string.Equals(key, "server.ConnectionDisconnect", StringComparison.Ordinal)) - { - value = ConnectionDisconnect; - return true; - } - break; - case 51: - if (((_flag1 & 0x2u) != 0) && string.Equals(key, "Microsoft.AspNet.Server.WebListener.OwinWebListener", StringComparison.Ordinal)) - { - value = Listener; - return true; - } - break; - } - value = null; - return false; - } - - private bool PropertiesTrySetValue(string key, object value) - { - switch (key.Length) - { - case 11: - if (string.Equals(key, "server.User", StringComparison.Ordinal)) - { - User = (System.Security.Principal.IPrincipal)value; - return true; - } - break; - case 12: - if (string.Equals(key, "owin.Version", StringComparison.Ordinal)) - { - OwinVersion = (string)value; - return true; - } - if (string.Equals(key, "host.AppName", StringComparison.Ordinal)) - { - HostAppName = (string)value; - return true; - } - if (string.Equals(key, "host.AppMode", StringComparison.Ordinal)) - { - HostAppMode = (string)value; - return true; - } - break; - case 14: - if (string.Equals(key, "server.IsLocal", StringComparison.Ordinal)) - { - IsLocal = (bool)value; - return true; - } - if (string.Equals(key, "opaque.Upgrade", StringComparison.Ordinal)) - { - OpaqueUpgrade = (OpaqueUpgrade)value; - return true; - } - break; - case 16: - if (string.Equals(key, "owin.RequestPath", StringComparison.Ordinal)) - { - RequestPath = (string)value; - return true; - } - if (string.Equals(key, "owin.RequestBody", StringComparison.Ordinal)) - { - RequestBody = (Stream)value; - return true; - } - if (string.Equals(key, "host.TraceOutput", StringComparison.Ordinal)) - { - HostTraceOutput = (TextWriter)value; - return true; - } - if (string.Equals(key, "server.LocalPort", StringComparison.Ordinal)) - { - LocalPort = (string)value; - return true; - } - break; - case 17: - if (string.Equals(key, "owin.ResponseBody", StringComparison.Ordinal)) - { - ResponseBody = (Stream)value; - return true; - } - if (string.Equals(key, "server.RemotePort", StringComparison.Ordinal)) - { - RemotePort = (string)value; - return true; - } - break; - case 18: - if (string.Equals(key, "owin.CallCancelled", StringComparison.Ordinal)) - { - CallCancelled = (CancellationToken)value; - return true; - } - if (string.Equals(key, "owin.RequestMethod", StringComparison.Ordinal)) - { - RequestMethod = (string)value; - return true; - } - if (string.Equals(key, "owin.RequestScheme", StringComparison.Ordinal)) - { - RequestScheme = (string)value; - return true; - } - if (string.Equals(key, "ssl.ChannelBinding", StringComparison.Ordinal)) - { - ChannelBinding = (ChannelBinding)value; - return true; - } - if (string.Equals(key, "sendfile.SendAsync", StringComparison.Ordinal)) - { - SendFileAsync = (Func)value; - return true; - } - break; - case 19: - if (string.Equals(key, "owin.RequestHeaders", StringComparison.Ordinal)) - { - RequestHeaders = (IDictionary)value; - return true; - } - if (string.Equals(key, "host.OnAppDisposing", StringComparison.Ordinal)) - { - OnAppDisposing = (CancellationToken)value; - return true; - } - if (string.Equals(key, "server.Capabilities", StringComparison.Ordinal)) - { - ServerCapabilities = (IDictionary)value; - return true; - } - if (string.Equals(key, "server.ConnectionId", StringComparison.Ordinal)) - { - ConnectionId = (object)value; - return true; - } - break; - case 20: - if (string.Equals(key, "owin.RequestProtocol", StringComparison.Ordinal)) - { - RequestProtocol = (string)value; - return true; - } - if (string.Equals(key, "owin.RequestPathBase", StringComparison.Ordinal)) - { - RequestPathBase = (string)value; - return true; - } - if (string.Equals(key, "owin.ResponseHeaders", StringComparison.Ordinal)) - { - ResponseHeaders = (IDictionary)value; - return true; - } - break; - case 21: - if (string.Equals(key, "server.LocalIpAddress", StringComparison.Ordinal)) - { - LocalIpAddress = (string)value; - return true; - } - if (string.Equals(key, "ssl.ClientCertificate", StringComparison.Ordinal)) - { - ClientCert = (object)value; - return true; - } - break; - case 22: - if (string.Equals(key, "server.RemoteIpAddress", StringComparison.Ordinal)) - { - RemoteIpAddress = (string)value; - return true; - } - break; - case 23: - if (string.Equals(key, "owin.RequestQueryString", StringComparison.Ordinal)) - { - RequestQueryString = (string)value; - return true; - } - if (string.Equals(key, "owin.ResponseStatusCode", StringComparison.Ordinal)) - { - ResponseStatusCode = (int?)value; - return true; - } - if (string.Equals(key, "server.OnSendingHeaders", StringComparison.Ordinal)) - { - OnSendingHeaders = (Action, object>)value; - return true; - } - if (string.Equals(key, "ssl.LoadClientCertAsync", StringComparison.Ordinal)) - { - LoadClientCert = (Func)value; - return true; - } - break; - case 25: - if (string.Equals(key, "owin.ResponseReasonPhrase", StringComparison.Ordinal)) - { - ResponseReasonPhrase = (string)value; - return true; - } - break; - case 27: - if (string.Equals(key, "server.ConnectionDisconnect", StringComparison.Ordinal)) - { - ConnectionDisconnect = (CancellationToken)value; - return true; - } - break; - case 51: - if (string.Equals(key, "Microsoft.AspNet.Server.WebListener.OwinWebListener", StringComparison.Ordinal)) - { - Listener = (OwinWebListener)value; - return true; - } - break; - } - return false; - } - - private bool PropertiesTryRemove(string key) - { - switch (key.Length) - { - case 11: - if (((_flag0 & 0x40000u) != 0) && string.Equals(key, "server.User", StringComparison.Ordinal)) - { - _flag0 &= ~0x40000u; - _User = default(System.Security.Principal.IPrincipal); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 12: - if (((_flag0 & 0x1u) != 0) && string.Equals(key, "owin.Version", StringComparison.Ordinal)) - { - _flag0 &= ~0x1u; - _OwinVersion = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x8000u) != 0) && string.Equals(key, "host.AppName", StringComparison.Ordinal)) - { - _flag0 &= ~0x8000u; - _HostAppName = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x10000u) != 0) && string.Equals(key, "host.AppMode", StringComparison.Ordinal)) - { - _flag0 &= ~0x10000u; - _HostAppMode = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 14: - if (((_flag0 & 0x2000000u) != 0) && string.Equals(key, "server.IsLocal", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x2000000u; - _flag0 &= ~0x2000000u; - _IsLocal = default(bool); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag1 & 0x1u) != 0) && string.Equals(key, "opaque.Upgrade", StringComparison.Ordinal)) - { - _initFlag1 &= ~0x1u; - _flag1 &= ~0x1u; - _OpaqueUpgrade = default(OpaqueUpgrade); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 16: - if (((_flag0 & 0x40u) != 0) && string.Equals(key, "owin.RequestPath", StringComparison.Ordinal)) - { - _flag0 &= ~0x40u; - _RequestPath = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x200u) != 0) && string.Equals(key, "owin.RequestBody", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x200u; - _flag0 &= ~0x200u; - _RequestBody = default(Stream); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x4000u) != 0) && string.Equals(key, "host.TraceOutput", StringComparison.Ordinal)) - { - _flag0 &= ~0x4000u; - _HostTraceOutput = default(TextWriter); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x1000000u) != 0) && string.Equals(key, "server.LocalPort", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x1000000u; - _flag0 &= ~0x1000000u; - _LocalPort = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 17: - if (((_flag0 & 0x800u) != 0) && string.Equals(key, "owin.ResponseBody", StringComparison.Ordinal)) - { - _flag0 &= ~0x800u; - _ResponseBody = default(Stream); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x400000u) != 0) && string.Equals(key, "server.RemotePort", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x400000u; - _flag0 &= ~0x400000u; - _RemotePort = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 18: - if (((_flag0 & 0x2u) != 0) && string.Equals(key, "owin.CallCancelled", StringComparison.Ordinal)) - { - _flag0 &= ~0x2u; - _CallCancelled = default(CancellationToken); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x8u) != 0) && string.Equals(key, "owin.RequestMethod", StringComparison.Ordinal)) - { - _flag0 &= ~0x8u; - _RequestMethod = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x10u) != 0) && string.Equals(key, "owin.RequestScheme", StringComparison.Ordinal)) - { - _flag0 &= ~0x10u; - _RequestScheme = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x40000000u) != 0) && string.Equals(key, "ssl.ChannelBinding", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x40000000u; - _flag0 &= ~0x40000000u; - _ChannelBinding = default(ChannelBinding); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x80000000u) != 0) && string.Equals(key, "sendfile.SendAsync", StringComparison.Ordinal)) - { - _flag0 &= ~0x80000000u; - _SendFileAsync = default(Func); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 19: - if (((_flag0 & 0x100u) != 0) && string.Equals(key, "owin.RequestHeaders", StringComparison.Ordinal)) - { - _flag0 &= ~0x100u; - _RequestHeaders = default(IDictionary); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x20000u) != 0) && string.Equals(key, "host.OnAppDisposing", StringComparison.Ordinal)) - { - _flag0 &= ~0x20000u; - _OnAppDisposing = default(CancellationToken); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x100000u) != 0) && string.Equals(key, "server.Capabilities", StringComparison.Ordinal)) - { - _flag0 &= ~0x100000u; - _ServerCapabilities = default(IDictionary); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x4000000u) != 0) && string.Equals(key, "server.ConnectionId", StringComparison.Ordinal)) - { - _flag0 &= ~0x4000000u; - _ConnectionId = default(object); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 20: - if (((_flag0 & 0x4u) != 0) && string.Equals(key, "owin.RequestProtocol", StringComparison.Ordinal)) - { - _flag0 &= ~0x4u; - _RequestProtocol = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x20u) != 0) && string.Equals(key, "owin.RequestPathBase", StringComparison.Ordinal)) - { - _flag0 &= ~0x20u; - _RequestPathBase = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x400u) != 0) && string.Equals(key, "owin.ResponseHeaders", StringComparison.Ordinal)) - { - _flag0 &= ~0x400u; - _ResponseHeaders = default(IDictionary); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 21: - if (((_flag0 & 0x800000u) != 0) && string.Equals(key, "server.LocalIpAddress", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x800000u; - _flag0 &= ~0x800000u; - _LocalIpAddress = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x10000000u) != 0) && string.Equals(key, "ssl.ClientCertificate", StringComparison.Ordinal)) - { - _flag0 &= ~0x10000000u; - _ClientCert = default(object); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 22: - if (((_flag0 & 0x200000u) != 0) && string.Equals(key, "server.RemoteIpAddress", StringComparison.Ordinal)) - { - _initFlag0 &= ~0x200000u; - _flag0 &= ~0x200000u; - _RemoteIpAddress = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 23: - if (((_flag0 & 0x80u) != 0) && string.Equals(key, "owin.RequestQueryString", StringComparison.Ordinal)) - { - _flag0 &= ~0x80u; - _RequestQueryString = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x1000u) != 0) && string.Equals(key, "owin.ResponseStatusCode", StringComparison.Ordinal)) - { - _flag0 &= ~0x1000u; - _ResponseStatusCode = default(int?); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x80000u) != 0) && string.Equals(key, "server.OnSendingHeaders", StringComparison.Ordinal)) - { - _flag0 &= ~0x80000u; - _OnSendingHeaders = default(Action, object>); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - if (((_flag0 & 0x20000000u) != 0) && string.Equals(key, "ssl.LoadClientCertAsync", StringComparison.Ordinal)) - { - _flag0 &= ~0x20000000u; - _LoadClientCert = default(Func); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 25: - if (((_flag0 & 0x2000u) != 0) && string.Equals(key, "owin.ResponseReasonPhrase", StringComparison.Ordinal)) - { - _flag0 &= ~0x2000u; - _ResponseReasonPhrase = default(string); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 27: - if (((_flag0 & 0x8000000u) != 0) && string.Equals(key, "server.ConnectionDisconnect", StringComparison.Ordinal)) - { - _flag0 &= ~0x8000000u; - _ConnectionDisconnect = default(CancellationToken); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - case 51: - if (((_flag1 & 0x2u) != 0) && string.Equals(key, "Microsoft.AspNet.Server.WebListener.OwinWebListener", StringComparison.Ordinal)) - { - _flag1 &= ~0x2u; - _Listener = default(OwinWebListener); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } - break; - } - return false; - } - - private IEnumerable PropertiesKeys() - { - if (((_flag0 & 0x1u) != 0)) - { - yield return "owin.Version"; - } - if (((_flag0 & 0x2u) != 0)) - { - yield return "owin.CallCancelled"; - } - if (((_flag0 & 0x4u) != 0)) - { - yield return "owin.RequestProtocol"; - } - if (((_flag0 & 0x8u) != 0)) - { - yield return "owin.RequestMethod"; - } - if (((_flag0 & 0x10u) != 0)) - { - yield return "owin.RequestScheme"; - } - if (((_flag0 & 0x20u) != 0)) - { - yield return "owin.RequestPathBase"; - } - if (((_flag0 & 0x40u) != 0)) - { - yield return "owin.RequestPath"; - } - if (((_flag0 & 0x80u) != 0)) - { - yield return "owin.RequestQueryString"; - } - if (((_flag0 & 0x100u) != 0)) - { - yield return "owin.RequestHeaders"; - } - if (((_flag0 & 0x200u) != 0)) - { - yield return "owin.RequestBody"; - } - if (((_flag0 & 0x400u) != 0)) - { - yield return "owin.ResponseHeaders"; - } - if (((_flag0 & 0x800u) != 0)) - { - yield return "owin.ResponseBody"; - } - if (((_flag0 & 0x1000u) != 0)) - { - yield return "owin.ResponseStatusCode"; - } - if (((_flag0 & 0x2000u) != 0)) - { - yield return "owin.ResponseReasonPhrase"; - } - if (((_flag0 & 0x4000u) != 0)) - { - yield return "host.TraceOutput"; - } - if (((_flag0 & 0x8000u) != 0)) - { - yield return "host.AppName"; - } - if (((_flag0 & 0x10000u) != 0)) - { - yield return "host.AppMode"; - } - if (((_flag0 & 0x20000u) != 0)) - { - yield return "host.OnAppDisposing"; - } - if (((_flag0 & 0x40000u) != 0)) - { - yield return "server.User"; - } - if (((_flag0 & 0x80000u) != 0)) - { - yield return "server.OnSendingHeaders"; - } - if (((_flag0 & 0x100000u) != 0)) - { - yield return "server.Capabilities"; - } - if (((_flag0 & 0x200000u) != 0)) - { - yield return "server.RemoteIpAddress"; - } - if (((_flag0 & 0x400000u) != 0)) - { - yield return "server.RemotePort"; - } - if (((_flag0 & 0x800000u) != 0)) - { - yield return "server.LocalIpAddress"; - } - if (((_flag0 & 0x1000000u) != 0)) - { - yield return "server.LocalPort"; - } - if (((_flag0 & 0x2000000u) != 0)) - { - yield return "server.IsLocal"; - } - if (((_flag0 & 0x4000000u) != 0)) - { - yield return "server.ConnectionId"; - } - if (((_flag0 & 0x8000000u) != 0)) - { - yield return "server.ConnectionDisconnect"; - } - if (((_flag0 & 0x10000000u) != 0)) - { - yield return "ssl.ClientCertificate"; - } - if (((_flag0 & 0x20000000u) != 0)) - { - yield return "ssl.LoadClientCertAsync"; - } - if (((_flag0 & 0x40000000u) != 0)) - { - if (((_initFlag0 & 0x40000000u) == 0) || InitPropertyChannelBinding()) - { - yield return "ssl.ChannelBinding"; - } - } - if (((_flag0 & 0x80000000u) != 0)) - { - yield return "sendfile.SendAsync"; - } - if (((_flag1 & 0x1u) != 0)) - { - if (((_initFlag1 & 0x1u) == 0) || InitPropertyOpaqueUpgrade()) - { - yield return "opaque.Upgrade"; - } - } - if (((_flag1 & 0x2u) != 0)) - { - yield return "Microsoft.AspNet.Server.WebListener.OwinWebListener"; - } - } - - private IEnumerable PropertiesValues() - { - if (((_flag0 & 0x1u) != 0)) - { - yield return OwinVersion; - } - if (((_flag0 & 0x2u) != 0)) - { - yield return CallCancelled; - } - if (((_flag0 & 0x4u) != 0)) - { - yield return RequestProtocol; - } - if (((_flag0 & 0x8u) != 0)) - { - yield return RequestMethod; - } - if (((_flag0 & 0x10u) != 0)) - { - yield return RequestScheme; - } - if (((_flag0 & 0x20u) != 0)) - { - yield return RequestPathBase; - } - if (((_flag0 & 0x40u) != 0)) - { - yield return RequestPath; - } - if (((_flag0 & 0x80u) != 0)) - { - yield return RequestQueryString; - } - if (((_flag0 & 0x100u) != 0)) - { - yield return RequestHeaders; - } - if (((_flag0 & 0x200u) != 0)) - { - yield return RequestBody; - } - if (((_flag0 & 0x400u) != 0)) - { - yield return ResponseHeaders; - } - if (((_flag0 & 0x800u) != 0)) - { - yield return ResponseBody; - } - if (((_flag0 & 0x1000u) != 0)) - { - yield return ResponseStatusCode; - } - if (((_flag0 & 0x2000u) != 0)) - { - yield return ResponseReasonPhrase; - } - if (((_flag0 & 0x4000u) != 0)) - { - yield return HostTraceOutput; - } - if (((_flag0 & 0x8000u) != 0)) - { - yield return HostAppName; - } - if (((_flag0 & 0x10000u) != 0)) - { - yield return HostAppMode; - } - if (((_flag0 & 0x20000u) != 0)) - { - yield return OnAppDisposing; - } - if (((_flag0 & 0x40000u) != 0)) - { - yield return User; - } - if (((_flag0 & 0x80000u) != 0)) - { - yield return OnSendingHeaders; - } - if (((_flag0 & 0x100000u) != 0)) - { - yield return ServerCapabilities; - } - if (((_flag0 & 0x200000u) != 0)) - { - yield return RemoteIpAddress; - } - if (((_flag0 & 0x400000u) != 0)) - { - yield return RemotePort; - } - if (((_flag0 & 0x800000u) != 0)) - { - yield return LocalIpAddress; - } - if (((_flag0 & 0x1000000u) != 0)) - { - yield return LocalPort; - } - if (((_flag0 & 0x2000000u) != 0)) - { - yield return IsLocal; - } - if (((_flag0 & 0x4000000u) != 0)) - { - yield return ConnectionId; - } - if (((_flag0 & 0x8000000u) != 0)) - { - yield return ConnectionDisconnect; - } - if (((_flag0 & 0x10000000u) != 0)) - { - yield return ClientCert; - } - if (((_flag0 & 0x20000000u) != 0)) - { - yield return LoadClientCert; - } - if (((_flag0 & 0x40000000u) != 0)) - { - if (((_initFlag0 & 0x40000000u) == 0) || InitPropertyChannelBinding()) - { - yield return ChannelBinding; - } - } - if (((_flag0 & 0x80000000u) != 0)) - { - yield return SendFileAsync; - } - if (((_flag1 & 0x1u) != 0)) - { - if (((_initFlag1 & 0x1u) == 0) || InitPropertyOpaqueUpgrade()) - { - yield return OpaqueUpgrade; - } - } - if (((_flag1 & 0x2u) != 0)) - { - yield return Listener; - } - } - - private IEnumerable> PropertiesEnumerable() - { - if (((_flag0 & 0x1u) != 0)) - { - yield return new KeyValuePair("owin.Version", OwinVersion); - } - if (((_flag0 & 0x2u) != 0)) - { - yield return new KeyValuePair("owin.CallCancelled", CallCancelled); - } - if (((_flag0 & 0x4u) != 0)) - { - yield return new KeyValuePair("owin.RequestProtocol", RequestProtocol); - } - if (((_flag0 & 0x8u) != 0)) - { - yield return new KeyValuePair("owin.RequestMethod", RequestMethod); - } - if (((_flag0 & 0x10u) != 0)) - { - yield return new KeyValuePair("owin.RequestScheme", RequestScheme); - } - if (((_flag0 & 0x20u) != 0)) - { - yield return new KeyValuePair("owin.RequestPathBase", RequestPathBase); - } - if (((_flag0 & 0x40u) != 0)) - { - yield return new KeyValuePair("owin.RequestPath", RequestPath); - } - if (((_flag0 & 0x80u) != 0)) - { - yield return new KeyValuePair("owin.RequestQueryString", RequestQueryString); - } - if (((_flag0 & 0x100u) != 0)) - { - yield return new KeyValuePair("owin.RequestHeaders", RequestHeaders); - } - if (((_flag0 & 0x200u) != 0)) - { - yield return new KeyValuePair("owin.RequestBody", RequestBody); - } - if (((_flag0 & 0x400u) != 0)) - { - yield return new KeyValuePair("owin.ResponseHeaders", ResponseHeaders); - } - if (((_flag0 & 0x800u) != 0)) - { - yield return new KeyValuePair("owin.ResponseBody", ResponseBody); - } - if (((_flag0 & 0x1000u) != 0)) - { - yield return new KeyValuePair("owin.ResponseStatusCode", ResponseStatusCode); - } - if (((_flag0 & 0x2000u) != 0)) - { - yield return new KeyValuePair("owin.ResponseReasonPhrase", ResponseReasonPhrase); - } - if (((_flag0 & 0x4000u) != 0)) - { - yield return new KeyValuePair("host.TraceOutput", HostTraceOutput); - } - if (((_flag0 & 0x8000u) != 0)) - { - yield return new KeyValuePair("host.AppName", HostAppName); - } - if (((_flag0 & 0x10000u) != 0)) - { - yield return new KeyValuePair("host.AppMode", HostAppMode); - } - if (((_flag0 & 0x20000u) != 0)) - { - yield return new KeyValuePair("host.OnAppDisposing", OnAppDisposing); - } - if (((_flag0 & 0x40000u) != 0)) - { - yield return new KeyValuePair("server.User", User); - } - if (((_flag0 & 0x80000u) != 0)) - { - yield return new KeyValuePair("server.OnSendingHeaders", OnSendingHeaders); - } - if (((_flag0 & 0x100000u) != 0)) - { - yield return new KeyValuePair("server.Capabilities", ServerCapabilities); - } - if (((_flag0 & 0x200000u) != 0)) - { - yield return new KeyValuePair("server.RemoteIpAddress", RemoteIpAddress); - } - if (((_flag0 & 0x400000u) != 0)) - { - yield return new KeyValuePair("server.RemotePort", RemotePort); - } - if (((_flag0 & 0x800000u) != 0)) - { - yield return new KeyValuePair("server.LocalIpAddress", LocalIpAddress); - } - if (((_flag0 & 0x1000000u) != 0)) - { - yield return new KeyValuePair("server.LocalPort", LocalPort); - } - if (((_flag0 & 0x2000000u) != 0)) - { - yield return new KeyValuePair("server.IsLocal", IsLocal); - } - if (((_flag0 & 0x4000000u) != 0)) - { - yield return new KeyValuePair("server.ConnectionId", ConnectionId); - } - if (((_flag0 & 0x8000000u) != 0)) - { - yield return new KeyValuePair("server.ConnectionDisconnect", ConnectionDisconnect); - } - if (((_flag0 & 0x10000000u) != 0)) - { - yield return new KeyValuePair("ssl.ClientCertificate", ClientCert); - } - if (((_flag0 & 0x20000000u) != 0)) - { - yield return new KeyValuePair("ssl.LoadClientCertAsync", LoadClientCert); - } - if (((_flag0 & 0x40000000u) != 0)) - { - if (((_initFlag0 & 0x40000000u) == 0) || InitPropertyChannelBinding()) - { - yield return new KeyValuePair("ssl.ChannelBinding", ChannelBinding); - } - } - if (((_flag0 & 0x80000000u) != 0)) - { - yield return new KeyValuePair("sendfile.SendAsync", SendFileAsync); - } - if (((_flag1 & 0x1u) != 0)) - { - if (((_initFlag1 & 0x1u) == 0) || InitPropertyOpaqueUpgrade()) - { - yield return new KeyValuePair("opaque.Upgrade", OpaqueUpgrade); - } - } - if (((_flag1 & 0x2u) != 0)) - { - yield return new KeyValuePair("Microsoft.AspNet.Server.WebListener.OwinWebListener", Listener); - } - } - } -} diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.Generated.tt b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.Generated.tt deleted file mode 100644 index 41a1b3db06..0000000000 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.Generated.tt +++ /dev/null @@ -1,316 +0,0 @@ -<#@ template language="C#" #> -<#@ assembly name="System.Core.dll" #> -<#@ import namespace="System.Linq" #> -<# -var Init = new {Yes = new object(), No = new object(), Maybe = new object()}; - -var props = new[] -{ -// owin standard keys - new {Key="owin.Version", Type="string", Name="OwinVersion", Init=Init.No}, - new {Key="owin.CallCancelled", Type="CancellationToken", Name="CallCancelled", Init=Init.No}, - - new {Key="owin.RequestProtocol", Type="string", Name="RequestProtocol", Init=Init.No}, - new {Key="owin.RequestMethod", Type="string", Name="RequestMethod", Init=Init.No}, - new {Key="owin.RequestScheme", Type="string", Name="RequestScheme", Init=Init.No}, - new {Key="owin.RequestPathBase", Type="string", Name="RequestPathBase", Init=Init.No}, - new {Key="owin.RequestPath", Type="string", Name="RequestPath", Init=Init.No}, - new {Key="owin.RequestQueryString", Type="string", Name="RequestQueryString", Init=Init.No}, - new {Key="owin.RequestHeaders", Type="IDictionary", Name="RequestHeaders", Init=Init.No}, - new {Key="owin.RequestBody", Type="Stream", Name="RequestBody", Init=Init.Yes}, - - new {Key="owin.ResponseHeaders", Type="IDictionary", Name="ResponseHeaders", Init=Init.No}, - new {Key="owin.ResponseBody", Type="Stream", Name="ResponseBody", Init=Init.No}, - new {Key="owin.ResponseStatusCode", Type="int?", Name="ResponseStatusCode", Init=Init.No}, - new {Key="owin.ResponseReasonPhrase", Type="string", Name="ResponseReasonPhrase", Init=Init.No}, - -// defacto host keys - new {Key="host.TraceOutput", Type="TextWriter", Name="HostTraceOutput", Init=Init.No}, - new {Key="host.AppName", Type="string", Name="HostAppName", Init=Init.No}, - new {Key="host.AppMode", Type="string", Name="HostAppMode", Init=Init.No}, - new {Key="host.OnAppDisposing", Type="CancellationToken", Name="OnAppDisposing", Init=Init.No}, - new {Key="server.User", Type="System.Security.Principal.IPrincipal", Name="User", Init=Init.No}, - new {Key="server.OnSendingHeaders", Type="Action, object>", Name="OnSendingHeaders", Init=Init.No}, - new {Key="server.Capabilities", Type="IDictionary", Name="ServerCapabilities", Init=Init.No}, - -// ServerVariable keys - new {Key="server.RemoteIpAddress", Type="string", Name="RemoteIpAddress", Init=Init.Yes}, - new {Key="server.RemotePort", Type="string", Name="RemotePort", Init=Init.Yes}, - new {Key="server.LocalIpAddress", Type="string", Name="LocalIpAddress", Init=Init.Yes}, - new {Key="server.LocalPort", Type="string", Name="LocalPort", Init=Init.Yes}, - new {Key="server.IsLocal", Type="bool", Name="IsLocal", Init=Init.Yes}, - new {Key="server.ConnectionId", Type="object", Name="ConnectionId", Init=Init.No}, - new {Key="server.ConnectionDisconnect", Type="CancellationToken", Name="ConnectionDisconnect", Init=Init.No}, - -// SSL - new { Key="ssl.ClientCertificate", Type="object", Name="ClientCert", Init=Init.No}, - new { Key="ssl.LoadClientCertAsync", Type="Func", Name="LoadClientCert", Init=Init.No }, - new { Key="ssl.ChannelBinding", Type="ChannelBinding", Name="ChannelBinding", Init=Init.Maybe }, - -// SendFile keys - new {Key="sendfile.SendAsync", Type="Func", Name="SendFileAsync", Init=Init.No}, - -// Opaque keys - new {Key="opaque.Upgrade", Type="OpaqueUpgrade", Name="OpaqueUpgrade", Init=Init.Maybe}, - -// Server specific keys - new { Key="Microsoft.AspNet.Server.WebListener.OwinWebListener", Type="OwinWebListener", Name="Listener", Init=Init.No}, -}.Select((prop, Index)=>new {prop.Key, prop.Type, prop.Name, prop.Init, Index}); - -var lengths = props.OrderBy(prop=>prop.Key.Length).GroupBy(prop=>prop.Key.Length); - -Func IsSet = Index => "((_flag" + (Index / 32) + " & 0x" + (1<<(Index % 32)).ToString("x") + "u) != 0)"; -Func Set = Index => "_flag" + (Index / 32) + " |= 0x" + (1<<(Index % 32)).ToString("x") + "u"; -Func Clear = Index => "_flag" + (Index / 32) + " &= ~0x" + (1<<(Index % 32)).ToString("x") + "u"; - -Func IsInitRequired = Index => "((_initFlag" + (Index / 32) + " & 0x" + (1<<(Index % 32)).ToString("x") + "u) != 0)"; -Func IsInitCompleted = Index => "((_initFlag" + (Index / 32) + " & 0x" + (1<<(Index % 32)).ToString("x") + "u) == 0)"; -Func CompleteInit = Index => "_initFlag" + (Index / 32) + " &= ~0x" + (1<<(Index % 32)).ToString("x") + "u"; - -#> -//----------------------------------------------------------------------- -// -// Copyright (c) Katana Contributors. All rights reserved. -// -//----------------------------------------------------------------------- -// - -using System; -using System.CodeDom.Compiler; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Security.Authentication.ExtendedProtection; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.Owin.Host.WebListener -{ - using OpaqueUpgrade = Action, Func, Task>>; - - [GeneratedCode("TextTemplatingFileGenerator", "")] - internal partial class CallEnvironment - { - // Mark all fields with delay initialization support as set. - private UInt32 _flag0 = 0x<#=props.Aggregate(0, (agg,p) => agg | (((p.Init != Init.No) && (p.Index/32==0) ? 1:0)<u; - private UInt32 _flag1 = 0x<#=props.Aggregate(0, (agg,p) => agg | (((p.Init != Init.No) && (p.Index/32==1) ? 1:0)<u; - // Mark all fields with delay initialization support as requiring initialization. - private UInt32 _initFlag0 = 0x<#=props.Aggregate(0, (agg,p) => agg | (((p.Init != Init.No) && (p.Index/32==0) ? 1:0)<u; - private UInt32 _initFlag1 = 0x<#=props.Aggregate(0, (agg,p) => agg | (((p.Init != Init.No) && (p.Index/32==1) ? 1:0)<u; - - internal interface IPropertySource - { -<# foreach(var prop in props) { #> -<# if (prop.Init == Init.Yes) { #> - <#=prop.Type#> Get<#=prop.Name#>(); -<# } #> -<# if (prop.Init == Init.Maybe) { #> - bool TryGet<#=prop.Name#>(ref <#=prop.Type#> value); -<# } #> -<# } #> - } - -<# foreach(var prop in props) { #> - private <#=prop.Type#> _<#=prop.Name#>; -<# } #> - -<# foreach(var prop in props) { #> -<# // call TryGet once if init flag is set, clear value flag if TryGet returns false -if (prop.Init == Init.Maybe) { #> - bool InitProperty<#=prop.Name#>() - { - if (!_propertySource.TryGet<#=prop.Name#>(ref _<#=prop.Name#>)) - { - <#=Clear(prop.Index)#>; - <#=CompleteInit(prop.Index)#>; - return false; - } - <#=CompleteInit(prop.Index)#>; - return true; - } - -<# } #> -<# } #> -<# foreach(var prop in props) { #> - internal <#=prop.Type#> <#=prop.Name#> - { - get - { -<# // call Get once if init flag is set -if (prop.Init == Init.Yes) { #> - if (<#=IsInitRequired(prop.Index)#>) - { - _<#=prop.Name#> = _propertySource.Get<#=prop.Name#>(); - <#=CompleteInit(prop.Index)#>; - } -<# } #> -<# // call TryGet once if init flag is set, clear value flag if TryGet returns false -if (prop.Init == Init.Maybe) { #> - if (<#=IsInitRequired(prop.Index)#>) - { - InitProperty<#=prop.Name#>(); - } -<# } #> - return _<#=prop.Name#>; - } - set - { -<# // clear init flag - the assigned value is definitive -if (prop.Init != Init.No) { #> - <#=CompleteInit(prop.Index)#>; -<# } #> - <#=Set(prop.Index)#>; - _<#=prop.Name#> = value; - } - } - -<# } #> - private bool PropertiesContainsKey(string key) - { - switch (key.Length) - { -<# foreach(var length in lengths) { #> - case <#=length.Key#>: -<# foreach(var prop in length) { #> - if (<#=IsSet(prop.Index)#> && string.Equals(key, "<#=prop.Key#>", StringComparison.Ordinal)) - { -<# // variable maybe init might revert -if (prop.Init == Init.Maybe) { #> - if (<#=IsInitCompleted(prop.Index)#> || InitProperty<#=prop.Name#>()) - { - return true; - } -<# } else { #> - return true; -<# } #> - } -<# } #> - break; -<# } #> - } - return false; - } - - private bool PropertiesTryGetValue(string key, out object value) - { - switch (key.Length) - { -<# foreach(var length in lengths) { #> - case <#=length.Key#>: -<# foreach(var prop in length) { #> - if (<#=IsSet(prop.Index)#> && string.Equals(key, "<#=prop.Key#>", StringComparison.Ordinal)) - { - value = <#=prop.Name#>; -<# if (prop.Init == Init.Maybe) { #> - // Delayed initialization in the property getter may determine that the element is not actually present - if (!<#=IsSet(prop.Index)#>) - { - value = default(<#=prop.Type#>); - return false; - } -<# } #> - return true; - } -<# } #> - break; -<# } #> - } - value = null; - return false; - } - - private bool PropertiesTrySetValue(string key, object value) - { - switch (key.Length) - { -<# foreach(var length in lengths) { #> - case <#=length.Key#>: -<# foreach(var prop in length) { #> - if (string.Equals(key, "<#=prop.Key#>", StringComparison.Ordinal)) - { - <#=prop.Name#> = (<#=prop.Type#>)value; - return true; - } -<# } #> - break; -<# } #> - } - return false; - } - - private bool PropertiesTryRemove(string key) - { - switch (key.Length) - { -<# foreach(var length in lengths) { #> - case <#=length.Key#>: -<# foreach(var prop in length) { #> - if (<#=IsSet(prop.Index)#> && string.Equals(key, "<#=prop.Key#>", StringComparison.Ordinal)) - { -<# if (prop.Init != Init.No) { #> - <#=CompleteInit(prop.Index)#>; -<# } #> - <#=Clear(prop.Index)#>; - _<#=prop.Name#> = default(<#=prop.Type#>); - // This can return true incorrectly for values that delayed initialization may determine are not actually present. - return true; - } -<# } #> - break; -<# } #> - } - return false; - } - - private IEnumerable PropertiesKeys() - { -<# foreach(var prop in props) { #> - if (<#=IsSet(prop.Index)#>) - { -<# if (prop.Init == Init.Maybe) { #> - if (<#=IsInitCompleted(prop.Index)#> || InitProperty<#=prop.Name#>()) - { - yield return "<#=prop.Key#>"; - } -<# } else { #> - yield return "<#=prop.Key#>"; -<# } #> - } -<# } #> - } - - private IEnumerable PropertiesValues() - { -<# foreach(var prop in props) { #> - if (<#=IsSet(prop.Index)#>) - { -<# if (prop.Init == Init.Maybe) { #> - if (<#=IsInitCompleted(prop.Index)#> || InitProperty<#=prop.Name#>()) - { - yield return <#=prop.Name#>; - } -<# } else { #> - yield return <#=prop.Name#>; -<# } #> - } -<# } #> - } - - private IEnumerable> PropertiesEnumerable() - { -<# foreach(var prop in props) { #> - if (<#=IsSet(prop.Index)#>) - { -<# if (prop.Init == Init.Maybe) { #> - if (<#=IsInitCompleted(prop.Index)#> || InitProperty<#=prop.Name#>()) - { - yield return new KeyValuePair("<#=prop.Key#>", <#=prop.Name#>); - } -<# } else { #> - yield return new KeyValuePair("<#=prop.Key#>", <#=prop.Name#>); -<# } #> - } -<# } #> - } - } -} diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.cs b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.cs deleted file mode 100644 index 360a2ea245..0000000000 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/CallEnvironment.cs +++ /dev/null @@ -1,165 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -// ----------------------------------------------------------------------- -// Copyright 2011-2012 Katana contributors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Threading; - -namespace Microsoft.AspNet.Server.WebListener -{ - internal partial class CallEnvironment : IDictionary - { - private static readonly IDictionary WeakNilEnvironment = new NilEnvDictionary(); - - private readonly IPropertySource _propertySource; - private IDictionary _extra = WeakNilEnvironment; - - internal CallEnvironment(IPropertySource propertySource) - { - _propertySource = propertySource; - } - - private IDictionary Extra - { - get { return _extra; } - } - - private IDictionary StrongExtra - { - get - { - if (_extra == WeakNilEnvironment) - { - Interlocked.CompareExchange(ref _extra, new Dictionary(), WeakNilEnvironment); - } - return _extra; - } - } - - internal bool IsExtraDictionaryCreated - { - get { return _extra != WeakNilEnvironment; } - } - - public object this[string key] - { - get - { - object value; - return PropertiesTryGetValue(key, out value) ? value : Extra[key]; - } - set - { - if (!PropertiesTrySetValue(key, value)) - { - StrongExtra[key] = value; - } - } - } - - public void Add(string key, object value) - { - if (!PropertiesTrySetValue(key, value)) - { - StrongExtra.Add(key, value); - } - } - - public bool ContainsKey(string key) - { - return PropertiesContainsKey(key) || Extra.ContainsKey(key); - } - - public ICollection Keys - { - get { return PropertiesKeys().Concat(Extra.Keys).ToArray(); } - } - - public bool Remove(string key) - { - // Although this is a mutating operation, Extra is used instead of StrongExtra, - // because if a real dictionary has not been allocated the default behavior of the - // nil dictionary is perfectly fine. - return PropertiesTryRemove(key) || Extra.Remove(key); - } - - public bool TryGetValue(string key, out object value) - { - return PropertiesTryGetValue(key, out value) || Extra.TryGetValue(key, out value); - } - - public ICollection Values - { - get { return PropertiesValues().Concat(Extra.Values).ToArray(); } - } - - public void Add(KeyValuePair item) - { - ((IDictionary)this).Add(item.Key, item.Value); - } - - public void Clear() - { - foreach (var key in PropertiesKeys()) - { - PropertiesTryRemove(key); - } - Extra.Clear(); - } - - public bool Contains(KeyValuePair item) - { - object value; - return ((IDictionary)this).TryGetValue(item.Key, out value) && Object.Equals(value, item.Value); - } - - public void CopyTo(KeyValuePair[] array, int arrayIndex) - { - PropertiesEnumerable().Concat(Extra).ToArray().CopyTo(array, arrayIndex); - } - - public int Count - { - get { return PropertiesKeys().Count() + Extra.Count; } - } - - public bool IsReadOnly - { - get { return false; } - } - - public bool Remove(KeyValuePair item) - { - return ((IDictionary)this).Contains(item) && - ((IDictionary)this).Remove(item.Key); - } - - public IEnumerator> GetEnumerator() - { - return PropertiesEnumerable().Concat(Extra).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IDictionary)this).GetEnumerator(); - } - } -} diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Request.cs b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Request.cs index 86b25185fb..dcf3100e30 100644 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Request.cs +++ b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Request.cs @@ -10,14 +10,18 @@ using System.Globalization; using System.IO; using System.Net; using System.Runtime.InteropServices; +#if NET45 using System.Security.Authentication.ExtendedProtection; +using System.Security.Cryptography.X509Certificates; +#endif using System.Security.Principal; -using System.Text; using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNet.HttpFeature; namespace Microsoft.AspNet.Server.WebListener { - internal sealed unsafe class Request : IDisposable + internal sealed class Request : IHttpRequestInformation, IHttpConnection, IHttpTransportLayerSecurity, IDisposable { private RequestContext _requestContext; private NativeRequestContext _nativeRequestContext; @@ -27,29 +31,46 @@ namespace Microsoft.AspNet.Server.WebListener private ulong _contextId; private SslStatus _sslStatus; + private string _scheme; private string _httpMethod; private Version _httpVersion; + private string _httpProtocolVersion; - private Uri _requestUri; + // private Uri _requestUri; private string _rawUrl; private string _cookedUrlHost; private string _cookedUrlPath; private string _cookedUrlQuery; + private string _pathBase; + private string _path; - private RequestHeaders _headers; +#if NET45 + private X509Certificate _clientCert; +#endif + + private IDictionary _headers; private BoundaryType _contentBoundaryType; private long _contentLength; + private Stream _nativeStream; private Stream _requestStream; + private SocketAddress _localEndPoint; private SocketAddress _remoteEndPoint; +#if NET45 + private IPAddress _remoteIpAddress; + private IPAddress _localIpAddress; +#endif + private int? _remotePort; + private int? _localPort; + private bool? _isLocal; private IPrincipal _user; private bool _isDisposed = false; private CancellationTokenRegistration _disconnectRegistration; - internal Request(RequestContext httpContext, NativeRequestContext memoryBlob) + internal unsafe Request(RequestContext httpContext, NativeRequestContext memoryBlob) { // TODO: Verbose log _requestContext = httpContext; @@ -82,6 +103,24 @@ namespace Microsoft.AspNet.Server.WebListener _cookedUrlQuery = Marshal.PtrToStringUni((IntPtr)cookedUrl.pQueryString, cookedUrl.QueryStringLength / 2); } + Prefix prefix = httpContext.Server.UriPrefixes[(int)_contextId]; + string orriginalPath = RequestPath; + + // These paths are both unescaped already. + if (orriginalPath.Length == prefix.Path.Length - 1) + { + // They matched exactly except for the trailing slash. + _pathBase = orriginalPath; + _path = string.Empty; + } + else + { + // url: /base/path, prefix: /base/, base: /base, path: /path + // url: /, prefix: /, base: , path: / + _pathBase = orriginalPath.Substring(0, prefix.Path.Length - 1); + _path = orriginalPath.Substring(prefix.Path.Length - 1); + } + int major = memoryBlob.RequestBlob->Version.MajorVersion; int minor = memoryBlob.RequestBlob->Version.MinorVersion; if (major == 1 && minor == 1) @@ -155,16 +194,16 @@ namespace Microsoft.AspNet.Server.WebListener } } - // Without the leading ? - internal string Query + // With the leading ?, if any + public string QueryString { get { - if (!string.IsNullOrWhiteSpace(_cookedUrlQuery)) - { - return _cookedUrlQuery.Substring(1); - } - return string.Empty; + return _cookedUrlQuery ?? string.Empty; + } + set + { + _cookedUrlQuery = value; } } @@ -176,6 +215,25 @@ namespace Microsoft.AspNet.Server.WebListener } } +#if NET45 + X509Certificate IHttpTransportLayerSecurity.ClientCertificate + { + get + { + if (_clientCert == null) + { + // TODO: Sync + ((IHttpTransportLayerSecurity)this).LoadAsync().Wait(); + } + return _clientCert; + } + set + { + _clientCert = value; + } + } +#endif + // TODO: Move this to the constructor, that's where it will be called. internal long ContentLength64 { @@ -210,40 +268,101 @@ namespace Microsoft.AspNet.Server.WebListener } } - internal IDictionary Headers + public IDictionary Headers { get { return _headers; } + set + { + if (value == null) + { + throw new ArgumentNullException("value"); + } + _headers = value; + } } - internal string HttpMethod + public string Method { get { return _httpMethod; } + set + { + _httpMethod = value; + } } - internal Stream InputStream + internal Stream NativeStream + { + get + { + if (_nativeStream == null) + { + // TODO: Move this to the constructor (or a lazy Env dictionary) + _nativeStream = HasEntityBody ? new RequestStream(RequestContext) : Stream.Null; + } + return _nativeStream; + } + } + + public Stream Body { get { if (_requestStream == null) { // TODO: Move this to the constructor (or a lazy Env dictionary) - _requestStream = HasEntityBody ? new RequestStream(RequestContext) : Stream.Null; + _requestStream = NativeStream; } return _requestStream; } + set + { + _requestStream = value; + } } - internal bool IsLocal + public string PathBase { get { - return LocalEndPoint.GetIPAddressString().Equals(RemoteEndPoint.GetIPAddressString()); + return _pathBase; + } + set + { + _pathBase = value; + } + } + + public string Path + { + get + { + return _path; + } + set + { + _path = value; + } + } + + public bool IsLocal + { + get + { + if (!_isLocal.HasValue) + { + _isLocal = LocalEndPoint.GetIPAddressString().Equals(RemoteEndPoint.GetIPAddressString()); + } + return _isLocal.Value; + } + set + { + _isLocal = value; } } @@ -254,7 +373,7 @@ namespace Microsoft.AspNet.Server.WebListener return _sslStatus != SslStatus.Insecure; } } - + /* internal string RawUrl { get @@ -262,7 +381,7 @@ namespace Microsoft.AspNet.Server.WebListener return _rawUrl; } } - + */ internal Version ProtocolVersion { get @@ -271,22 +390,34 @@ namespace Microsoft.AspNet.Server.WebListener } } - internal string Protocol + public string Protocol { get { - if (_httpVersion.Major == 1) + if (_httpProtocolVersion == null) { - if (_httpVersion.Minor == 1) + if (_httpVersion.Major == 1) { - return "HTTP/1.1"; + if (_httpVersion.Minor == 1) + { + _httpProtocolVersion = "HTTP/1.1"; + } + else if (_httpVersion.Minor == 0) + { + _httpProtocolVersion = "HTTP/1.0"; + } } - else if (_httpVersion.Minor == 0) + else { - return "HTTP/1.0"; + _httpProtocolVersion = "HTTP/" + _httpVersion.ToString(2); } } - return "HTTP/" + _httpVersion.ToString(2); + return _httpProtocolVersion; + } + set + { + // TODO: Set _httpVersion? + _httpProtocolVersion = value; } } @@ -326,15 +457,87 @@ namespace Microsoft.AspNet.Server.WebListener return _localEndPoint; } } - - internal string RequestScheme +#if NET45 + public IPAddress RemoteIpAddress { get { - return IsSecureConnection ? Constants.HttpsScheme : Constants.HttpScheme; + if (_remoteIpAddress == null) + { + _remoteIpAddress = IPAddress.Parse(RemoteEndPoint.GetIPAddressString()); // TODO: Create directly from bytes + } + return _remoteIpAddress; + } + set + { + _remoteIpAddress = value; } } + public IPAddress LocalIpAddress + { + get + { + if (_localIpAddress == null) + { + _localIpAddress = IPAddress.Parse(LocalEndPoint.GetIPAddressString()); // TODO: Create directly from bytes + } + return _localIpAddress; + } + set + { + _localIpAddress = value; + } + } +#endif + public int RemotePort + { + get + { + if (!_remotePort.HasValue) + { + _remotePort = RemoteEndPoint.GetPort(); + } + return _remotePort.Value; + } + set + { + _remotePort = value; + } + } + + public int LocalPort + { + get + { + if (!_localPort.HasValue) + { + _localPort = LocalEndPoint.GetPort(); + } + return _localPort.Value; + } + set + { + _localPort = value; + } + } + + public string Scheme + { + get + { + if (_scheme == null) + { + _scheme = IsSecureConnection ? Constants.HttpsScheme : Constants.HttpScheme; + } + return _scheme; + } + set + { + _scheme = value; + } + } + /* internal Uri RequestUri { get @@ -348,7 +551,7 @@ namespace Microsoft.AspNet.Server.WebListener return _requestUri; } } - + */ internal string RequestPath { get @@ -391,6 +594,47 @@ namespace Microsoft.AspNet.Server.WebListener #endif } + // Populates the client certificate. The result may be null if there is no client cert. + // TODO: Does it make sense for this to be invoked multiple times (e.g. renegotiate)? Client and server code appear to + // enable this, but it's unclear what Http.Sys would do. + async Task IHttpTransportLayerSecurity.LoadAsync() + { + if (SslStatus == SslStatus.Insecure) + { + // Non-SSL + return; + } + // TODO: Verbose log +#if NET45 + if (_clientCert != null) + { + return; + } + + ClientCertLoader certLoader = new ClientCertLoader(RequestContext); + try + { + await certLoader.LoadClientCertificateAsync().SupressContext(); + // Populate the environment. + if (certLoader.ClientCert != null) + { + _clientCert = certLoader.ClientCert; + } + // TODO: Expose errors and exceptions? + } + catch (Exception) + { + if (certLoader != null) + { + certLoader.Dispose(); + } + throw; + } +#else + throw new NotImplementedException(); +#endif + } + // Use this to save the blob from dispose if this object was never used (never given to a user) and is about to be // disposed. internal void DetachBlob(NativeRequestContext memoryBlob) @@ -419,9 +663,9 @@ namespace Microsoft.AspNet.Server.WebListener _nativeRequestContext = null; } _disconnectRegistration.Dispose(); - if (_requestStream != null) + if (_nativeStream != null) { - _requestStream.Dispose(); + _nativeStream.Dispose(); } } @@ -435,9 +679,9 @@ namespace Microsoft.AspNet.Server.WebListener internal void SwitchToOpaqueMode() { - if (_requestStream == null || _requestStream == Stream.Null) + if (_nativeStream == null || _nativeStream == Stream.Null) { - _requestStream = new RequestStream(RequestContext); + _nativeStream = new RequestStream(RequestContext); } } diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/RequestContext.cs b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/RequestContext.cs index 5cb122006c..934ed1eb87 100644 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/RequestContext.cs +++ b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/RequestContext.cs @@ -15,17 +15,19 @@ using System.Runtime.InteropServices; using System.Security.Authentication.ExtendedProtection; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; namespace Microsoft.AspNet.Server.WebListener { using LoggerFunc = Func, bool>; using OpaqueFunc = Func, Task>; - internal sealed class RequestContext : IDisposable, CallEnvironment.IPropertySource + internal sealed class RequestContext : IDisposable { private static readonly string[] ZeroContentLength = new[] { "0" }; - private CallEnvironment _environment; + private FeatureCollection _features; private OwinWebListener _server; private Request _request; private Response _response; @@ -41,17 +43,17 @@ namespace Microsoft.AspNet.Server.WebListener _memoryBlob = memoryBlob; _request = new Request(this, _memoryBlob); _response = new Response(this); - _environment = new CallEnvironment(this); _cts = new CancellationTokenSource(); - PopulateEnvironment(); + _features = new FeatureCollection(); + PopulateFeatures(); _request.ReleasePins(); } - internal CallEnvironment Environment + internal IFeatureCollection Features { - get { return _environment; } + get { return _features; } } internal Request Request @@ -99,105 +101,31 @@ namespace Microsoft.AspNet.Server.WebListener } } - private void PopulateEnvironment() + private void PopulateFeatures() { - // General - _environment.OwinVersion = Constants.OwinVersion; - _environment.CallCancelled = _cts.Token; + _features.Add(typeof(IHttpRequestInformation), Request); + _features.Add(typeof(IHttpConnection), Request); + if (Request.IsSecureConnection) + { + // TODO: Should this feature be conditional? Should we add this for HTTP requests? + _features.Add(typeof(IHttpTransportLayerSecurity), Request); + } + _features.Add(typeof(IHttpResponseInformation), Response); + _features.Add(typeof(IHttpSendFile), Response); + // TODO: + // _environment.CallCancelled = _cts.Token; + // _environment.User = _request.User; + // Opaque/WebSockets + // Channel binding + + /* // Server - _environment.ServerCapabilities = _server.Capabilities; _environment.Listener = _server; - - // Request - _environment.RequestProtocol = _request.Protocol; - _environment.RequestMethod = _request.HttpMethod; - _environment.RequestScheme = _request.RequestScheme; - _environment.RequestQueryString = _request.Query; - _environment.RequestHeaders = _request.Headers; - - SetPaths(); - - _environment.ConnectionId = _request.ConnectionId; - - if (_request.IsSecureConnection) - { - _environment.LoadClientCert = LoadClientCertificateAsync; - } - - if (_request.User != null) - { - _environment.User = _request.User; - } - - // Response - _environment.ResponseStatusCode = 200; - _environment.ResponseHeaders = _response.Headers; - _environment.ResponseBody = _response.OutputStream; - _environment.SendFileAsync = _response.SendFileAsync; - - _environment.OnSendingHeaders = _response.RegisterForOnSendingHeaders; - - Contract.Assert(!_environment.IsExtraDictionaryCreated, - "All server keys should have a reserved slot in the environment."); + _environment.ConnectionId = _request.ConnectionId; + */ } - - // Find the closest matching prefix and use it to separate the request path in to path and base path. - // Scheme and port must match. Path will use a longest match. Host names are more complicated due to - // wildcards, IP addresses, etc. - private void SetPaths() - { - Prefix prefix = _server.UriPrefixes[(int)Request.ContextId]; - string orriginalPath = _request.RequestPath; - - // These paths are both unescaped already. - if (orriginalPath.Length == prefix.Path.Length - 1) - { - // They matched exactly except for the trailing slash. - _environment.RequestPathBase = orriginalPath; - _environment.RequestPath = string.Empty; - } - else - { - // url: /base/path, prefix: /base/, base: /base, path: /path - // url: /, prefix: /, base: , path: / - _environment.RequestPathBase = orriginalPath.Substring(0, prefix.Path.Length - 1); - _environment.RequestPath = orriginalPath.Substring(prefix.Path.Length - 1); - } - } - - // Lazy environment init - - public Stream GetRequestBody() - { - return _request.InputStream; - } - - public string GetRemoteIpAddress() - { - return _request.RemoteEndPoint.GetIPAddressString(); - } - - public string GetRemotePort() - { - return _request.RemoteEndPoint.GetPort().ToString(CultureInfo.InvariantCulture.NumberFormat); - } - - public string GetLocalIpAddress() - { - return _request.LocalEndPoint.GetIPAddressString(); - } - - public string GetLocalPort() - { - return _request.LocalEndPoint.GetPort().ToString(CultureInfo.InvariantCulture.NumberFormat); - } - - public bool GetIsLocal() - { - return _request.IsLocal; - } - + /* public bool TryGetOpaqueUpgrade(ref Action, OpaqueFunc> value) { if (_request.IsUpgradable) @@ -213,6 +141,7 @@ namespace Microsoft.AspNet.Server.WebListener value = Server.GetChannelBinding(Request.ConnectionId, Request.IsSecureConnection); return value != null; } + */ public void Dispose() { @@ -290,42 +219,6 @@ namespace Microsoft.AspNet.Server.WebListener } } - // Populates the environment ClicentCertificate. The result may be null if there is no client cert. - // TODO: Does it make sense for this to be invoked multiple times (e.g. renegotiate)? Client and server code appear to - // enable this, but it's unclear what Http.Sys would do. - private async Task LoadClientCertificateAsync() - { - if (Request.SslStatus == SslStatus.Insecure) - { - // Non-SSL - return; - } - // TODO: Verbose log -#if NET45 - ClientCertLoader certLoader = new ClientCertLoader(this); - try - { - await certLoader.LoadClientCertificateAsync().SupressContext(); - // Populate the environment. - if (certLoader.ClientCert != null) - { - Environment.ClientCert = certLoader.ClientCert; - } - // TODO: Expose errors and exceptions? - } - catch (Exception) - { - if (certLoader != null) - { - certLoader.Dispose(); - } - throw; - } -#else - throw new NotImplementedException(); -#endif - } - internal void OpaqueUpgrade(IDictionary parameters, OpaqueFunc callback) { // Parameters are ignored for now @@ -339,8 +232,8 @@ namespace Microsoft.AspNet.Server.WebListener } // Set the status code and reason phrase - Environment.ResponseStatusCode = (int)HttpStatusCode.SwitchingProtocols; - Environment.ResponseReasonPhrase = HttpReasonPhrase.Get(HttpStatusCode.SwitchingProtocols); + Response.StatusCode = (int)HttpStatusCode.SwitchingProtocols; + Response.ReasonPhrase = HttpReasonPhrase.Get(HttpStatusCode.SwitchingProtocols); // Store the callback and process it after the stack unwind. _opaqueCallback = callback; @@ -351,7 +244,7 @@ namespace Microsoft.AspNet.Server.WebListener { // If an upgrade was requested, perform it if (!Response.SentHeaders && _opaqueCallback != null - && Environment.ResponseStatusCode == (int)HttpStatusCode.SwitchingProtocols) + && Response.StatusCode == (int)HttpStatusCode.SwitchingProtocols) { Response.SendOpaqueUpgrade(); @@ -368,21 +261,21 @@ namespace Microsoft.AspNet.Server.WebListener opaqueEnv[Constants.OpaqueVersionKey] = Constants.OpaqueVersion; // TODO: Separate CT? - opaqueEnv[Constants.OpaqueCallCancelledKey] = Environment.CallCancelled; + // opaqueEnv[Constants.OpaqueCallCancelledKey] = Environment.CallCancelled; Request.SwitchToOpaqueMode(); Response.SwitchToOpaqueMode(); - opaqueEnv[Constants.OpaqueStreamKey] = new OpaqueStream(Request.InputStream, Response.OutputStream); + opaqueEnv[Constants.OpaqueStreamKey] = new OpaqueStream(Request.NativeStream, Response.NativeStream); return opaqueEnv; } internal void SetFatalResponse() { - Environment.ResponseStatusCode = 500; - Environment.ResponseReasonPhrase = string.Empty; - Environment.ResponseHeaders.Clear(); - Environment.ResponseHeaders.Add(HttpKnownHeaderNames.ContentLength, ZeroContentLength); + Response.StatusCode = 500; + Response.ReasonPhrase = string.Empty; + Response.Headers.Clear(); + Response.Headers.Add(HttpKnownHeaderNames.ContentLength, ZeroContentLength); } } } diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Response.cs b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Response.cs index d25af63ed7..9f2ac4807d 100644 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Response.cs +++ b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/Response.cs @@ -14,14 +14,17 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.HttpFeature; namespace Microsoft.AspNet.Server.WebListener { - internal sealed unsafe class Response : IDisposable + internal sealed unsafe class Response : IHttpResponseInformation, IHttpSendFile, IDisposable { private ResponseState _responseState; private IDictionary _headers; - private ResponseStream _responseStream; + private string _reasonPhrase; + private ResponseStream _nativeStream; + private Stream _responseStream; private long _contentLength; private BoundaryType _boundaryType; private UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE _nativeResponse; @@ -67,31 +70,55 @@ namespace Microsoft.AspNet.Server.WebListener } } - internal Stream OutputStream + public int StatusCode + { + get { return _nativeResponse.StatusCode; } + set + { + if (value <= 100 || 999 < value) + { + throw new ArgumentOutOfRangeException("value", value, string.Format(Resources.Exception_InvalidStatusCode, value)); + } + _nativeResponse.StatusCode = (ushort)value; + } + } + + public string ReasonPhrase + { + get { return _reasonPhrase; } + set { _reasonPhrase = value; } + } + + internal ResponseStream NativeStream { get { CheckDisposed(); EnsureResponseStream(); - return _responseStream; + return _nativeStream; } } - internal int GetStatusCode() + public Stream Body { - int statusCode = _requestContext.Environment.ResponseStatusCode ?? 200; - if (statusCode <= 100 || statusCode > 999) + get { - // TODO: Move this validation to the dictionary facade so it throws when the app sets it, rather than durring send? - throw new InvalidOperationException(string.Format(Resources.Exception_InvalidStatusCode, statusCode)); + if (_responseStream == null) + { + _responseStream = NativeStream; + } + return _responseStream; + } + set + { + _responseStream = value; } - return statusCode; } internal string GetReasonPhrase(int statusCode) { // TODO: Validate user input for illegal chars, length limit, etc.? - string reasonPhrase = _requestContext.Environment.ResponseReasonPhrase; + string reasonPhrase = ReasonPhrase; if (string.IsNullOrWhiteSpace(reasonPhrase)) { // if the user hasn't set this, generated on the fly, if possible. @@ -124,11 +151,16 @@ namespace Microsoft.AspNet.Server.WebListener } } - internal IDictionary Headers + public IDictionary Headers { - get + get { return _headers; } + set { - return _headers; + if (value == null) + { + throw new ArgumentNullException("value"); + } + _headers = value; } } @@ -142,6 +174,7 @@ namespace Microsoft.AspNet.Server.WebListener private Version GetProtocolVersion() { + /* Version requestVersion = Request.ProtocolVersion; Version responseVersion = requestVersion; string protocolVersion = RequestContext.Environment.Get(Constants.HttpResponseProtocolKey); @@ -170,7 +203,11 @@ namespace Microsoft.AspNet.Server.WebListener } // Return the lesser of the two versions. There are only two, so it it will always be 1.0. - return Constants.V1_0; + return Constants.V1_0;*/ + + // TODO: IHttpResponseInformation does not define a response protocol version. Http.Sys doesn't let + // us send anything but 1.1 anyways, but we could at least use it to set things like the connection header. + return Request.ProtocolVersion; } public void Dispose() @@ -188,7 +225,7 @@ namespace Microsoft.AspNet.Server.WebListener } // TODO: Verbose log EnsureResponseStream(); - _responseStream.Dispose(); + _nativeStream.Dispose(); _responseState = ResponseState.Closed; } } @@ -221,9 +258,9 @@ namespace Microsoft.AspNet.Server.WebListener private void EnsureResponseStream() { - if (_responseStream == null) + if (_nativeStream == null) { - _responseStream = new ResponseStream(RequestContext); + _nativeStream = new ResponseStream(RequestContext); } } @@ -266,8 +303,6 @@ namespace Microsoft.AspNet.Server.WebListener // TODO: Verbose log headers _responseState = ResponseState.SentHeaders; - - _nativeResponse.StatusCode = (ushort)GetStatusCode(); string reasonPhrase = GetReasonPhrase(_nativeResponse.StatusCode); /* @@ -369,7 +404,7 @@ namespace Microsoft.AspNet.Server.WebListener NotifyOnSendingHeaders(); // 401 - if (GetStatusCode() == (ushort)HttpStatusCode.Unauthorized) + if (StatusCode == (ushort)HttpStatusCode.Unauthorized) { RequestContext.Server.AuthenticationManager.SetAuthenticationChallenge(this); } @@ -468,7 +503,7 @@ namespace Microsoft.AspNet.Server.WebListener _boundaryType = BoundaryType.Chunked; } - if (CanSendResponseBody(_requestContext.Response.GetStatusCode())) + if (CanSendResponseBody(_requestContext.Response.StatusCode)) { _contentLength = -1; } @@ -708,25 +743,25 @@ namespace Microsoft.AspNet.Server.WebListener internal void CancelLastWrite(SafeHandle requestQueueHandle) { - if (_responseStream != null) + if (_nativeStream != null) { - _responseStream.CancelLastWrite(requestQueueHandle); + _nativeStream.CancelLastWrite(requestQueueHandle); } } - internal Task SendFileAsync(string fileName, long offset, long? count, CancellationToken cancel) + public Task SendFileAsync(string path, long offset, long? count, CancellationToken cancel) { EnsureResponseStream(); - return _responseStream.SendFileAsync(fileName, offset, count, cancel); + return _nativeStream.SendFileAsync(path, offset, count, cancel); } internal void SwitchToOpaqueMode() { EnsureResponseStream(); - _responseStream.SwitchToOpaqueMode(); + _nativeStream.SwitchToOpaqueMode(); } - internal void RegisterForOnSendingHeaders(Action callback, object state) + public void OnSendingHeaders(Action callback, object state) { IList, object>> actions = _onSendingHeadersActions; if (actions == null) diff --git a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/ResponseStream.cs b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/ResponseStream.cs index 0177312901..84c29adefe 100644 --- a/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/ResponseStream.cs +++ b/src/Microsoft.AspNet.Server.WebListener/RequestProcessing/ResponseStream.cs @@ -736,7 +736,7 @@ namespace Microsoft.AspNet.Server.WebListener } uint statusCode = 0; - if ((_requestContext.Response.BoundaryType == BoundaryType.Chunked || _requestContext.Response.BoundaryType == BoundaryType.None) && (String.Compare(_requestContext.Request.HttpMethod, "HEAD", StringComparison.OrdinalIgnoreCase) != 0)) + if ((_requestContext.Response.BoundaryType == BoundaryType.Chunked || _requestContext.Response.BoundaryType == BoundaryType.None) && (String.Compare(_requestContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) != 0)) { if (_requestContext.Response.BoundaryType == BoundaryType.None) { diff --git a/src/Microsoft.AspNet.Server.WebListener/project.json b/src/Microsoft.AspNet.Server.WebListener/project.json index 0ba47798dd..cb109c3392 100644 --- a/src/Microsoft.AspNet.Server.WebListener/project.json +++ b/src/Microsoft.AspNet.Server.WebListener/project.json @@ -1,5 +1,10 @@ { "version": "0.1-alpha-*", + "dependencies": { + "Microsoft.AspNet.Abstractions" : "0.1-alpha-*", + "Microsoft.AspNet.HttpFeature" : "0.1-alpha-*", + "Microsoft.AspNet.FeatureModel" : "0.1-alpha-*" + }, "compilationOptions" : { "allowUnsafe": true }, "configurations": { "net45" : { }, diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/AuthenticationTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/AuthenticationTests.cs index d85855d66a..0259f84f43 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/AuthenticationTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/AuthenticationTests.cs @@ -9,12 +9,14 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.PipelineCore; using Xunit; using Xunit.Extensions; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class AuthenticationTests { @@ -49,7 +51,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(authType, env => { - env["owin.ResponseStatusCode"] = 401; + new DefaultHttpContext((IFeatureCollection)env).Response.StatusCode = 401; return Task.FromResult(0); })) { @@ -65,7 +67,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests // TODO: Not implemented - Digest using (CreateServer(AuthenticationType.Kerberos | AuthenticationType.Negotiate | AuthenticationType.Ntlm | /*AuthenticationType.Digest |*/ AuthenticationType.Basic, env => { - env["owin.ResponseStatusCode"] = 401; + new DefaultHttpContext((IFeatureCollection)env).Response.StatusCode = 401; return Task.FromResult(0); })) { @@ -74,26 +76,27 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal("Kerberos, Negotiate, NTLM, basic", response.Headers.WwwAuthenticate.ToString(), StringComparer.OrdinalIgnoreCase); } } - + /* TODO: User [Theory] [InlineData(AuthenticationType.Kerberos)] [InlineData(AuthenticationType.Negotiate)] [InlineData(AuthenticationType.Ntlm)] // [InlineData(AuthenticationType.Digest)] // TODO: Not implemented // [InlineData(AuthenticationType.Basic)] // Doesn't work with default creds - [InlineData(AuthenticationType.Kerberos | AuthenticationType.Negotiate | AuthenticationType.Ntlm | /*AuthenticationType.Digest |*/ AuthenticationType.Basic)] + [InlineData(AuthenticationType.Kerberos | AuthenticationType.Negotiate | AuthenticationType.Ntlm | / *AuthenticationType.Digest |* / AuthenticationType.Basic)] public async Task AuthTypes_Login_Success(AuthenticationType authType) { int requestCount = 0; using (CreateServer(authType, env => { requestCount++; + / * // TODO: Expose user as feature. object obj; if (env.TryGetValue("server.User", out obj) && obj != null) { return Task.FromResult(0); - } - env["owin.ResponseStatusCode"] = 401; + }* / + new DefaultHttpContext((IFeatureCollection)env).Response.StatusCode = 401; return Task.FromResult(0); })) { @@ -101,7 +104,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests response.EnsureSuccessStatusCode(); } } - + */ private IDisposable CreateServer(AuthenticationType authType, AppFunc app) { IDictionary properties = new Dictionary(); diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/HttpsTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/HttpsTests.cs index 98661a8380..c2e29eccde 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/HttpsTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/HttpsTests.cs @@ -11,11 +11,14 @@ using System.Net.Http; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class HttpsTests { @@ -39,10 +42,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); byte[] body = Encoding.UTF8.GetBytes("Hello World"); - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { body.Length.ToString() }; - return env.Get("owin.ResponseBody").WriteAsync(body, 0, body.Length); + httpContext.Response.ContentLength = body.Length; + return httpContext.Response.Body.WriteAsync(body, 0, body.Length); })) { string response = await SendRequestAsync(Address); @@ -55,12 +58,12 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - string input = new StreamReader(env.Get("owin.RequestBody")).ReadToEnd(); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + string input = new StreamReader(httpContext.Request.Body).ReadToEnd(); Assert.Equal("Hello World", input); byte[] body = Encoding.UTF8.GetBytes("Hello World"); - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { body.Length.ToString() }; - env.Get("owin.ResponseBody").Write(body, 0, body.Length); + httpContext.Response.ContentLength = body.Length; + httpContext.Response.Body.Write(body, 0, body.Length); return Task.FromResult(0); })) { @@ -72,38 +75,36 @@ namespace Microsoft.AspNet.Server.WebListener.Tests [Fact] public async Task Https_ClientCertNotSent_ClientCertNotPresent() { - X509Certificate clientCert = null; - using (CreateServer(env => + using (CreateServer(async env => { - var loadAsync = env.Get>("ssl.LoadClientCertAsync"); - loadAsync().Wait(); - clientCert = env.Get("ssl.ClientCertificate"); - return Task.FromResult(0); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var tls = httpContext.GetFeature(); + Assert.NotNull(tls); + await tls.LoadAsync(); + Assert.Null(tls.ClientCertificate); })) { string response = await SendRequestAsync(Address); Assert.Equal(string.Empty, response); - Assert.Null(clientCert); } } [Fact] public async Task Https_ClientCertRequested_ClientCertPresent() { - X509Certificate clientCert = null; - using (CreateServer(env => + using (CreateServer(async env => { - var loadAsync = env.Get>("ssl.LoadClientCertAsync"); - loadAsync().Wait(); - clientCert = env.Get("ssl.ClientCertificate"); - return Task.FromResult(0); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var tls = httpContext.GetFeature(); + Assert.NotNull(tls); + await tls.LoadAsync(); + Assert.NotNull(tls.ClientCertificate); })) { X509Certificate2 cert = FindClientCert(); Assert.NotNull(cert); string response = await SendRequestAsync(Address, cert); Assert.Equal(string.Empty, response); - Assert.NotNull(clientCert); } } diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/OpaqueUpgradeTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/OpaqueUpgradeTests.cs index 07c8610feb..e7ddf53495 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/OpaqueUpgradeTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/OpaqueUpgradeTests.cs @@ -3,7 +3,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // // ----------------------------------------------------------------------- - +/* TODO: Opaque using System; using System.Collections.Generic; using System.IO; @@ -17,7 +17,7 @@ using Xunit.Extensions; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; using OpaqueUpgrade = Action, Func, Task>>; public class OpaqueUpgradeTests @@ -322,3 +322,4 @@ namespace Microsoft.AspNet.Server.WebListener.Tests } } } +*/ \ No newline at end of file diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/RequestBodyTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/RequestBodyTests.cs index 3687766ca1..640d0dc489 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/RequestBodyTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/RequestBodyTests.cs @@ -11,11 +11,13 @@ using System.Net; using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class RequestBodyTests { @@ -26,12 +28,11 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); byte[] input = new byte[100]; - int read = env.Get("owin.RequestBody").Read(input, 0, input.Length); - - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { read.ToString() }; - env.Get("owin.ResponseBody").Write(input, 0, read); + int read = httpContext.Request.Body.Read(input, 0, input.Length); + httpContext.Response.ContentLength = read; + httpContext.Response.Body.Write(input, 0, read); return Task.FromResult(0); })) { @@ -45,32 +46,28 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(async env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); byte[] input = new byte[100]; - int read = await env.Get("owin.RequestBody").ReadAsync(input, 0, input.Length); - - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { read.ToString() }; - await env.Get("owin.ResponseBody").WriteAsync(input, 0, read); + int read = await httpContext.Request.Body.ReadAsync(input, 0, input.Length); + httpContext.Response.ContentLength = read; + await httpContext.Response.Body.WriteAsync(input, 0, read); })) { string response = await SendRequestAsync(Address, "Hello World"); Assert.Equal("Hello World", response); } } - +#if NET45 [Fact] public async Task RequestBody_ReadBeginEnd_Success() { using (CreateServer(env => { - Stream requestStream = env.Get("owin.RequestBody"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); byte[] input = new byte[100]; - int read = requestStream.EndRead(requestStream.BeginRead(input, 0, input.Length, null, null)); - - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { read.ToString() }; - Stream responseStream = env.Get("owin.ResponseBody"); - responseStream.EndWrite(responseStream.BeginWrite(input, 0, read, null, null)); + int read = httpContext.Request.Body.EndRead(httpContext.Request.Body.BeginRead(input, 0, input.Length, null, null)); + httpContext.Response.ContentLength = read; + httpContext.Response.Body.EndWrite(httpContext.Response.Body.BeginWrite(input, 0, read, null, null)); return Task.FromResult(0); })) { @@ -78,18 +75,19 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal("Hello World", response); } } - +#endif [Fact] public async Task RequestBody_ReadSyncPartialBody_Success() { StaggardContent content = new StaggardContent(); using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); byte[] input = new byte[10]; - int read = env.Get("owin.RequestBody").Read(input, 0, input.Length); + int read = httpContext.Request.Body.Read(input, 0, input.Length); Assert.Equal(5, read); content.Block.Release(); - read = env.Get("owin.RequestBody").Read(input, 0, input.Length); + read = httpContext.Request.Body.Read(input, 0, input.Length); Assert.Equal(5, read); return Task.FromResult(0); })) @@ -105,11 +103,12 @@ namespace Microsoft.AspNet.Server.WebListener.Tests StaggardContent content = new StaggardContent(); using (CreateServer(async env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); byte[] input = new byte[10]; - int read = await env.Get("owin.RequestBody").ReadAsync(input, 0, input.Length); + int read = await httpContext.Request.Body.ReadAsync(input, 0, input.Length); Assert.Equal(5, read); content.Block.Release(); - read = await env.Get("owin.RequestBody").ReadAsync(input, 0, input.Length); + read = await httpContext.Request.Body.ReadAsync(input, 0, input.Length); Assert.Equal(5, read); })) { diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/RequestHeaderTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/RequestHeaderTests.cs index a322ea06d0..9e2828c50d 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/RequestHeaderTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/RequestHeaderTests.cs @@ -10,11 +10,13 @@ using System.Net.Http; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class RequestHeaderTests { @@ -25,7 +27,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - var requestHeaders = env.Get>("owin.RequestHeaders"); + var requestHeaders = new DefaultHttpContext((IFeatureCollection)env).Request.Headers; // NOTE: The System.Net client only sends the Connection: keep-alive header on the first connection per service-point. // Assert.Equal(2, requestHeaders.Count); // Assert.Equal("Keep-Alive", requestHeaders.Get("Connection")); @@ -44,7 +46,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - var requestHeaders = env.Get>("owin.RequestHeaders"); + var requestHeaders = new DefaultHttpContext((IFeatureCollection)env).Request.Headers; Assert.Equal(4, requestHeaders.Count); Assert.Equal("localhost:8080", requestHeaders.Get("Host")); Assert.Equal("close", requestHeaders.Get("Connection")); diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/RequestTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/RequestTests.cs index a99bdafa86..11c0ce59d1 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/RequestTests.cs @@ -11,12 +11,15 @@ using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; using Xunit; using Xunit.Extensions; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class RequestTests { @@ -27,36 +30,40 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); try { // General keys - Assert.Equal("1.0", env.Get("owin.Version")); - Assert.True(env.Get("owin.CallCancelled").CanBeCanceled); + // TODO: Assert.True(env.Get("owin.CallCancelled").CanBeCanceled); + + var requestInfo = httpContext.GetFeature(); // Request Keys - Assert.Equal("GET", env.Get("owin.RequestMethod")); - Assert.Equal(Stream.Null, env.Get("owin.RequestBody")); - Assert.NotNull(env.Get>("owin.RequestHeaders")); - Assert.Equal("http", env.Get("owin.RequestScheme")); - Assert.Equal("/basepath", env.Get("owin.RequestPathBase")); - Assert.Equal("/SomePath", env.Get("owin.RequestPath")); - Assert.Equal("SomeQuery", env.Get("owin.RequestQueryString")); - Assert.Equal("HTTP/1.1", env.Get("owin.RequestProtocol")); + Assert.Equal("GET", requestInfo.Method); + Assert.Equal(Stream.Null, requestInfo.Body); + Assert.NotNull(requestInfo.Headers); + Assert.Equal("http", requestInfo.Scheme); + Assert.Equal("/basepath", requestInfo.PathBase); + Assert.Equal("/SomePath", requestInfo.Path); + Assert.Equal("?SomeQuery", requestInfo.QueryString); + Assert.Equal("HTTP/1.1", requestInfo.Protocol); // Server Keys - Assert.NotNull(env.Get>("server.Capabilities")); - Assert.Equal("::1", env.Get("server.RemoteIpAddress")); - Assert.NotNull(env.Get("server.RemotePort")); - Assert.Equal("::1", env.Get("server.LocalIpAddress")); - Assert.Equal("8080", env.Get("server.LocalPort")); - Assert.True(env.Get("server.IsLocal")); + // TODO: Assert.NotNull(env.Get>("server.Capabilities")); + + var connectionInfo = httpContext.GetFeature(); + Assert.Equal("::1", connectionInfo.RemoteIpAddress.ToString()); + Assert.NotEqual(0, connectionInfo.RemotePort); + Assert.Equal("::1", connectionInfo.LocalIpAddress.ToString()); + Assert.NotEqual(0, connectionInfo.LocalPort); + Assert.True(connectionInfo.IsLocal); // Note: Response keys are validated in the ResponseTests } catch (Exception ex) { byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); - env.Get("owin.ResponseBody").Write(body, 0, body.Length); + httpContext.Response.Body.Write(body, 0, body.Length); } return Task.FromResult(0); }, "http", "localhost", "8080", "/basepath")) @@ -78,21 +85,23 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); try { - Uri uri = new Uri(requestUri); - string expectedQuery = uri.Query.Length > 0 ? uri.Query.Substring(1) : string.Empty; + var requestInfo = httpContext.GetFeature(); + var connectionInfo = httpContext.GetFeature(); + // Request Keys - Assert.Equal(scheme, env.Get("owin.RequestScheme")); - Assert.Equal(expectedPath, env.Get("owin.RequestPath")); - Assert.Equal(expectedPathBase, env.Get("owin.RequestPathBase")); - Assert.Equal(expectedQuery, env.Get("owin.RequestQueryString")); - Assert.Equal(port, env.Get("server.LocalPort")); + Assert.Equal(scheme, requestInfo.Scheme); + Assert.Equal(expectedPath, requestInfo.Path); + Assert.Equal(expectedPathBase, requestInfo.PathBase); + Assert.Equal(string.Empty, requestInfo.QueryString); + Assert.Equal(port, connectionInfo.LocalPort.ToString()); } catch (Exception ex) { byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); - env.Get("owin.ResponseBody").Write(body, 0, body.Length); + httpContext.Response.Body.Write(body, 0, body.Length); } return Task.FromResult(0); }, scheme, host, port, pathBase)) @@ -119,15 +128,17 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var requestInfo = httpContext.GetFeature(); try { - Assert.Equal(expectedPath, env.Get("owin.RequestPath")); - Assert.Equal(expectedPathBase, env.Get("owin.RequestPathBase")); + Assert.Equal(expectedPath, requestInfo.Path); + Assert.Equal(expectedPathBase, requestInfo.PathBase); } catch (Exception ex) { byte[] body = Encoding.ASCII.GetBytes(ex.ToString()); - env.Get("owin.ResponseBody").Write(body, 0, body.Length); + httpContext.Response.Body.Write(body, 0, body.Length); } return Task.FromResult(0); })) diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseBodyTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseBodyTests.cs index bc95cb305f..ddcdc4aa2e 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseBodyTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseBodyTests.cs @@ -11,11 +11,14 @@ using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class ResponseBodyTests { @@ -26,8 +29,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get("owin.ResponseBody").Write(new byte[10], 0, 10); - return env.Get("owin.ResponseBody").WriteAsync(new byte[10], 0, 10); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.Body.Write(new byte[10], 0, 10); + return httpContext.Response.Body.WriteAsync(new byte[10], 0, 10); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -45,8 +49,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["transfeR-Encoding"] = new string[] { " CHunked " }; - Stream stream = env.Get("owin.ResponseBody"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Request.Headers["transfeR-Encoding"] = " CHunked "; + Stream stream = httpContext.Response.Body; stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null)); stream.Write(new byte[10], 0, 10); return stream.WriteAsync(new byte[10], 0, 10); @@ -67,8 +72,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { " 30 " }; - Stream stream = env.Get("owin.ResponseBody"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.Headers["Content-lenGth"] = " 30 "; + Stream stream = httpContext.Response.Body; stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null)); stream.Write(new byte[10], 0, 10); return stream.WriteAsync(new byte[10], 0, 10); @@ -84,7 +90,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal(new byte[30], await response.Content.ReadAsByteArrayAsync()); } } - + /* TODO: response protocol [Fact] public async Task ResponseBody_Http10WriteNoHeaders_DefaultsConnectionClose() { @@ -104,13 +110,14 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal(new byte[20], await response.Content.ReadAsByteArrayAsync()); } } - + */ [Fact] public void ResponseBody_WriteContentLengthNoneWritten_Throws() { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { " 20 " }; + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.Headers["Content-lenGth"] = " 20 "; return Task.FromResult(0); })) { @@ -123,8 +130,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { " 20 " }; - env.Get("owin.ResponseBody").Write(new byte[5], 0, 5); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.Headers["Content-lenGth"] = " 20 "; + httpContext.Response.Body.Write(new byte[5], 0, 5); return Task.FromResult(0); })) { @@ -137,9 +145,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { " 10 " }; - env.Get("owin.ResponseBody").Write(new byte[5], 0, 5); - env.Get("owin.ResponseBody").Write(new byte[6], 0, 6); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.Headers["Content-lenGth"] = " 10 "; + httpContext.Response.Body.Write(new byte[5], 0, 5); + httpContext.Response.Body.Write(new byte[6], 0, 6); return Task.FromResult(0); })) { @@ -156,9 +165,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { try { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { " 10 " }; - env.Get("owin.ResponseBody").Write(new byte[10], 0, 10); - env.Get("owin.ResponseBody").Write(new byte[9], 0, 9); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.Headers["Content-lenGth"] = " 10 "; + httpContext.Response.Body.Write(new byte[10], 0, 10); + httpContext.Response.Body.Write(new byte[9], 0, 9); appThrew = false; } catch (Exception) diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseHeaderTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseHeaderTests.cs index 56b3bb48f4..a4e9126992 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseHeaderTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseHeaderTests.cs @@ -10,11 +10,14 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class ResponseHeaderTests { @@ -44,7 +47,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - var responseHeaders = env.Get>("owin.ResponseHeaders"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var responseInfo = httpContext.GetFeature(); + var responseHeaders = responseInfo.Headers; responseHeaders["Custom-Header1"] = new string[] { "custom1, and custom2", "custom3" }; return Task.FromResult(0); })) @@ -66,7 +71,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - var responseHeaders = env.Get>("owin.ResponseHeaders"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var responseInfo = httpContext.GetFeature(); + var responseHeaders = responseInfo.Headers; responseHeaders["Connection"] = new string[] { "Close" }; return Task.FromResult(0); })) @@ -77,7 +84,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal(new string[] { "close" }, response.Headers.GetValues("Connection")); } } - + /* TODO: [Fact] public async Task ResponseHeaders_SendsHttp10_Gets11Close() { @@ -113,6 +120,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal(new string[] { "close" }, response.Headers.GetValues("Connection")); } } + */ [Fact] public async Task ResponseHeaders_HTTP10Request_Gets11Close() @@ -140,9 +148,11 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - var responseHeaders = env.Get>("owin.ResponseHeaders"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var responseInfo = httpContext.GetFeature(); + var responseHeaders = responseInfo.Headers; responseHeaders["Transfer-Encoding"] = new string[] { "chunked" }; - return env.Get("owin.ResponseBody").WriteAsync(new byte[10], 0, 10); + return responseInfo.Body.WriteAsync(new byte[10], 0, 10); })) { using (HttpClient client = new HttpClient()) @@ -166,12 +176,14 @@ namespace Microsoft.AspNet.Server.WebListener.Tests using (CreateServer( env => { - var responseHeaders = env.Get>("owin.ResponseHeaders"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var responseInfo = httpContext.GetFeature(); + var responseHeaders = responseInfo.Headers; responseHeaders.Add("Custom1", new string[] { "value1a", "value1b" }); responseHeaders.Add("Custom2", new string[] { "value2a, value2b" }); - var body = env.Get("owin.ResponseBody"); + var body = responseInfo.Body; body.Flush(); - env["owin.ResponseStatusCode"] = 404; // Ignored + responseInfo.StatusCode = 404; // Ignored responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" }); // Ignored return Task.FromResult(0); })) @@ -194,12 +206,14 @@ namespace Microsoft.AspNet.Server.WebListener.Tests using (CreateServer( async env => { - var responseHeaders = env.Get>("owin.ResponseHeaders"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var responseInfo = httpContext.GetFeature(); + var responseHeaders = responseInfo.Headers; responseHeaders.Add("Custom1", new string[] { "value1a", "value1b" }); responseHeaders.Add("Custom2", new string[] { "value2a, value2b" }); - var body = env.Get("owin.ResponseBody"); + var body = responseInfo.Body; await body.FlushAsync(); - env["owin.ResponseStatusCode"] = 404; // Ignored + responseInfo.StatusCode = 404; // Ignored responseHeaders.Add("Custom3", new string[] { "value3a, value3b", "value3c" }); // Ignored })) { diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseSendFileTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseSendFileTests.cs index d176dc2a1a..18912bbba2 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseSendFileTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseSendFileTests.cs @@ -13,12 +13,14 @@ using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; - using SendFileFunc = Func; + using AppFunc = Func; public class ResponseSendFileTests { @@ -32,8 +34,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { + var httpContext = new DefaultHttpContext((IFeatureCollection)env); try { + /* TODO: IDictionary capabilities = env.Get>("server.Capabilities"); Assert.NotNull(capabilities); @@ -43,14 +47,15 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.NotNull(support); Assert.Equal("Overlapped", support.Get("sendfile.Concurrency")); + */ - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - Assert.NotNull(sendFileAsync); + var sendFile = httpContext.GetFeature(); + Assert.NotNull(sendFile); } catch (Exception ex) { byte[] body = Encoding.UTF8.GetBytes(ex.ToString()); - env.Get("owin.ResponseBody").Write(body, 0, body.Length); + httpContext.Response.Body.Write(body, 0, body.Length); } return Task.FromResult(0); })) @@ -72,10 +77,11 @@ namespace Microsoft.AspNet.Server.WebListener.Tests bool? appThrew = null; using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); try { - sendFileAsync(string.Empty, 0, null, CancellationToken.None).Wait(); + sendFile.SendFileAsync(string.Empty, 0, null, CancellationToken.None).Wait(); appThrew = false; } catch (Exception) @@ -103,8 +109,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + return sendFile.SendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -121,8 +128,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(RelativeFilePath, 0, null, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + return sendFile.SendFileAsync(RelativeFilePath, 0, null, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -139,9 +147,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Transfer-EncodinG"] = new string[] { "CHUNKED" }; - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + httpContext.Response.Headers["Transfer-EncodinG"] = "CHUNKED"; + return sendFile.SendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -158,10 +167,11 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Transfer-EncodinG"] = new string[] { "CHUNKED" }; - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - sendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None).Wait(); - return sendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + httpContext.Response.Headers["Transfer-EncodinG"] = "CHUNKED"; + sendFile.SendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None).Wait(); + return sendFile.SendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -178,8 +188,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, FileLength / 2, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + return sendFile.SendFileAsync(AbsoluteFilePath, 0, FileLength / 2, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -196,8 +207,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 1234567, null, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + return sendFile.SendFileAsync(AbsoluteFilePath, 1234567, null, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -210,8 +222,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, 1234567, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + return sendFile.SendFileAsync(AbsoluteFilePath, 0, 1234567, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -224,8 +237,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, 0, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + return sendFile.SendFileAsync(AbsoluteFilePath, 0, 0, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -242,9 +256,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { FileLength.ToString() }; - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + httpContext.Response.Headers["Content-lenGth"] = FileLength.ToString(); + return sendFile.SendFileAsync(AbsoluteFilePath, 0, null, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -262,9 +277,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { "10" }; - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, 10, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + httpContext.Response.Headers["Content-lenGth"] = "10"; + return sendFile.SendFileAsync(AbsoluteFilePath, 0, 10, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); @@ -282,9 +298,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env.Get>("owin.ResponseHeaders")["Content-lenGth"] = new string[] { "0" }; - SendFileFunc sendFileAsync = env.Get("sendfile.SendAsync"); - return sendFileAsync(AbsoluteFilePath, 0, 0, CancellationToken.None); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + var sendFile = httpContext.GetFeature(); + httpContext.Response.Headers["Content-lenGth"] = "0"; + return sendFile.SendFileAsync(AbsoluteFilePath, 0, 0, CancellationToken.None); })) { HttpResponseMessage response = await SendRequestAsync(Address); diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseTests.cs index 537ad8c6c9..ae9562a94d 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/ResponseTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/ResponseTests.cs @@ -6,13 +6,17 @@ using System; using System.Collections.Generic; +using System.Net; using System.Net.Http; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.HttpFeature; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class ResponseTests { @@ -23,7 +27,8 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - Assert.Equal(200, env["owin.ResponseStatusCode"]); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + Assert.Equal(200, httpContext.Response.StatusCode); return Task.FromResult(0); })) { @@ -40,8 +45,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env["owin.ResponseStatusCode"] = 201; - env["owin.ResponseProtocol"] = "HTTP/1.0"; // Http.Sys ignores this value + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.StatusCode = 201; + // TODO: env["owin.ResponseProtocol"] = "HTTP/1.0"; // Http.Sys ignores this value return Task.FromResult(0); })) { @@ -58,9 +64,10 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env["owin.ResponseStatusCode"] = 201; - env["owin.ResponseReasonPhrase"] = "CustomReasonPhrase"; - env["owin.ResponseProtocol"] = "HTTP/1.0"; // Http.Sys ignores this value + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.StatusCode = 201; + httpContext.GetFeature().ReasonPhrase = "CustomReasonPhrase"; // TODO? + // TODO: env["owin.ResponseProtocol"] = "HTTP/1.0"; // Http.Sys ignores this value return Task.FromResult(0); })) { @@ -77,7 +84,8 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - env["owin.ResponseStatusCode"] = 901; + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.StatusCode = 901; return Task.FromResult(0); })) { @@ -89,28 +97,32 @@ namespace Microsoft.AspNet.Server.WebListener.Tests } [Fact] - public void Response_100_Throws() + public async Task Response_100_Throws() { using (CreateServer(env => { - env["owin.ResponseStatusCode"] = 100; + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.StatusCode = 100; return Task.FromResult(0); })) { - Assert.Throws(() => SendRequestAsync(Address).Result); + HttpResponseMessage response = await SendRequestAsync(Address); + Assert.Equal(500, (int)response.StatusCode); } } [Fact] - public void Response_0_Throws() + public async Task Response_0_Throws() { using (CreateServer(env => { - env["owin.ResponseStatusCode"] = 0; + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.StatusCode = 0; return Task.FromResult(0); })) { - Assert.Throws(() => SendRequestAsync(Address).Result); + HttpResponseMessage response = await SendRequestAsync(Address); + Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode); } } diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/ServerTests.cs b/test/Microsoft.AspNet.Server.WebListener.Test/ServerTests.cs index 84f76d9a52..f1c5c3e22a 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/ServerTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.Test/ServerTests.cs @@ -13,11 +13,13 @@ using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.FeatureModel; +using Microsoft.AspNet.PipelineCore; using Xunit; namespace Microsoft.AspNet.Server.WebListener.Tests { - using AppFunc = Func, Task>; + using AppFunc = Func; public class ServerTests { @@ -41,11 +43,9 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - byte[] body = Encoding.UTF8.GetBytes("Hello World"); - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { body.Length.ToString() }; - env.Get("owin.ResponseBody").Write(body, 0, body.Length); - return Task.FromResult(0); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + httpContext.Response.ContentLength = 11; + return httpContext.Response.WriteAsync("Hello World"); })) { string response = await SendRequestAsync(Address); @@ -58,13 +58,11 @@ namespace Microsoft.AspNet.Server.WebListener.Tests { using (CreateServer(env => { - string input = new StreamReader(env.Get("owin.RequestBody")).ReadToEnd(); + var httpContext = new DefaultHttpContext((IFeatureCollection)env); + string input = new StreamReader(httpContext.Request.Body).ReadToEnd(); Assert.Equal("Hello World", input); - byte[] body = Encoding.UTF8.GetBytes("Hello World"); - var responseHeaders = env.Get>("owin.ResponseHeaders"); - responseHeaders["Content-Length"] = new string[] { body.Length.ToString() }; - env.Get("owin.ResponseBody").Write(body, 0, body.Length); - return Task.FromResult(0); + httpContext.Response.ContentLength = 11; + return httpContext.Response.WriteAsync("Hello World"); })) { string response = await SendRequestAsync(Address, "Hello World"); @@ -154,7 +152,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.True(Task.WaitAll(requestTasks.ToArray(), TimeSpan.FromSeconds(2)), "Timed out"); } } - + /* TODO: [Fact] public async Task Server_ClientDisconnects_CallCancelled() { @@ -204,7 +202,7 @@ namespace Microsoft.AspNet.Server.WebListener.Tests Assert.Equal(string.Empty, response); } } - + */ private IDisposable CreateServer(AppFunc app) { IDictionary properties = new Dictionary(); diff --git a/test/Microsoft.AspNet.Server.WebListener.Test/project.json b/test/Microsoft.AspNet.Server.WebListener.Test/project.json index b11449f836..13c881b938 100644 --- a/test/Microsoft.AspNet.Server.WebListener.Test/project.json +++ b/test/Microsoft.AspNet.Server.WebListener.Test/project.json @@ -1,7 +1,11 @@ { "version" : "0.1-alpha-*", "dependencies": { - "Microsoft.AspNet.Server.WebListener" : "" + "Microsoft.AspNet.Server.WebListener" : "", + "Microsoft.AspNet.Abstractions" : "0.1-alpha-*", + "Microsoft.AspNet.HttpFeature" : "0.1-alpha-*", + "Microsoft.AspNet.FeatureModel" : "0.1-alpha-*", + "Microsoft.AspNet.PipelineCore" : "0.1-alpha-*" }, "configurations": { "net45": {