What about now?

This commit is contained in:
Pavel Krymets 2018-04-10 09:08:13 -07:00
parent 80e799d17c
commit ee2e46a614
4 changed files with 49 additions and 46 deletions

View File

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Description>ASP.NET Core components for working with the IIS AspNetCoreModule.</Description> <Description>ASP.NET Core components for working with the IIS AspNetCoreModule.</Description>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks> <TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn> <NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;iis</PackageTags> <PackageTags>aspnetcore;iis</PackageTags>

View File

@ -31,6 +31,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
protected readonly IntPtr _pInProcessHandler; protected readonly IntPtr _pInProcessHandler;
private readonly IISOptions _options;
private bool _reading; // To know whether we are currently in a read operation. private bool _reading; // To know whether we are currently in a read operation.
private volatile bool _hasResponseStarted; private volatile bool _hasResponseStarted;
@ -62,13 +64,45 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
internal unsafe IISHttpContext(MemoryPool<byte> memoryPool, IntPtr pInProcessHandler, IISOptions options, IISHttpServer server) internal unsafe IISHttpContext(MemoryPool<byte> memoryPool, IntPtr pInProcessHandler, IISOptions options, IISHttpServer server)
: base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.HttpGetRawRequest(pInProcessHandler)) : base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.HttpGetRawRequest(pInProcessHandler))
{ {
_thisHandle = GCHandle.Alloc(this);
_memoryPool = memoryPool; _memoryPool = memoryPool;
_pInProcessHandler = pInProcessHandler; _pInProcessHandler = pInProcessHandler;
_options = options;
_server = server; _server = server;
}
public Version HttpVersion { get; set; }
public string Scheme { get; set; }
public string Method { get; set; }
public string PathBase { get; set; }
public string Path { get; set; }
public string QueryString { get; set; }
public string RawTarget { get; set; }
public CancellationToken RequestAborted { get; set; }
public bool HasResponseStarted => _hasResponseStarted;
public IPAddress RemoteIpAddress { get; set; }
public int RemotePort { get; set; }
public IPAddress LocalIpAddress { get; set; }
public int LocalPort { get; set; }
public string RequestConnectionId { get; set; }
public string TraceIdentifier { get; set; }
public ClaimsPrincipal User { get; set; }
internal WindowsPrincipal WindowsUser { get; set; }
public Stream RequestBody { get; set; }
public Stream ResponseBody { get; set; }
public Pipe Input { get; set; }
public OutputProducer Output { get; set; }
public IHeaderDictionary RequestHeaders { get; set; }
public IHeaderDictionary ResponseHeaders { get; set; }
private HeaderCollection HttpResponseHeaders { get; set; }
internal HttpApiTypes.HTTP_VERB KnownMethod { get; private set; }
protected void InitializeContext()
{
_thisHandle = GCHandle.Alloc(this);
NativeMethods.HttpSetManagedContext(_pInProcessHandler, (IntPtr)_thisHandle);
NativeMethods.HttpSetManagedContext(pInProcessHandler, (IntPtr)_thisHandle);
Method = GetVerb(); Method = GetVerb();
RawTarget = GetRawUrl(); RawTarget = GetRawUrl();
@ -100,10 +134,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
HttpResponseHeaders = new HeaderCollection(); HttpResponseHeaders = new HeaderCollection();
ResponseHeaders = HttpResponseHeaders; ResponseHeaders = HttpResponseHeaders;
if (options.ForwardWindowsAuthentication) if (_options.ForwardWindowsAuthentication)
{ {
WindowsUser = GetWindowsPrincipal(); WindowsUser = GetWindowsPrincipal();
if (options.AutomaticAuthentication) if (_options.AutomaticAuthentication)
{ {
User = WindowsUser; User = WindowsUser;
} }
@ -111,7 +145,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
ResetFeatureCollection(); ResetFeatureCollection();
if (!_server.IsWebSocketAvailible(pInProcessHandler)) if (!_server.IsWebSocketAvailible(_pInProcessHandler))
{ {
_currentIHttpUpgradeFeature = null; _currentIHttpUpgradeFeature = null;
} }
@ -130,33 +164,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
Output = new OutputProducer(pipe); Output = new OutputProducer(pipe);
} }
public Version HttpVersion { get; set; }
public string Scheme { get; set; }
public string Method { get; set; }
public string PathBase { get; set; }
public string Path { get; set; }
public string QueryString { get; set; }
public string RawTarget { get; set; }
public CancellationToken RequestAborted { get; set; }
public bool HasResponseStarted => _hasResponseStarted;
public IPAddress RemoteIpAddress { get; set; }
public int RemotePort { get; set; }
public IPAddress LocalIpAddress { get; set; }
public int LocalPort { get; set; }
public string RequestConnectionId { get; set; }
public string TraceIdentifier { get; set; }
public ClaimsPrincipal User { get; set; }
internal WindowsPrincipal WindowsUser { get; set; }
public Stream RequestBody { get; set; }
public Stream ResponseBody { get; set; }
public Pipe Input { get; set; }
public OutputProducer Output { get; set; }
public IHeaderDictionary RequestHeaders { get; set; }
public IHeaderDictionary ResponseHeaders { get; set; }
private HeaderCollection HttpResponseHeaders { get; set; }
internal HttpApiTypes.HTTP_VERB KnownMethod { get; }
public int StatusCode public int StatusCode
{ {
get { return _statusCode; } get { return _statusCode; }

View File

@ -22,6 +22,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
public override async Task<bool> ProcessRequestAsync() public override async Task<bool> ProcessRequestAsync()
{ {
InitializeContext();
var context = default(TContext); var context = default(TContext);
var success = true; var success = true;

View File

@ -144,21 +144,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
var server = (IISHttpServer)GCHandle.FromIntPtr(pvRequestContext).Target; var server = (IISHttpServer)GCHandle.FromIntPtr(pvRequestContext).Target;
Interlocked.Increment(ref server._outstandingRequests); Interlocked.Increment(ref server._outstandingRequests);
#if NETCOREAPP2_1 var context = server._iisContextFactory.CreateHttpContext(pInProcessHandler);
ThreadPool.QueueUserWorkItem<(IISHttpServer, IntPtr)>(
state => _ = HandleRequest(state.Item1, state.Item2), ThreadPool.QueueUserWorkItem(state => _ = HandleRequest((IISHttpContext)state), context);
(server, pInProcessHandler),
preferLocal: false);
#else
ThreadPool.QueueUserWorkItem(
state => _ = HandleRequest(server, pInProcessHandler));
#endif
return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING; return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING;
} }
private static async Task HandleRequest(IISHttpServer server, IntPtr handler) private static async Task HandleRequest(IISHttpContext context)
{ {
var context = server._iisContextFactory.CreateHttpContext(handler);
var result = await context.ProcessRequestAsync(); var result = await context.ProcessRequestAsync();
CompleteRequest(context, result); CompleteRequest(context, result);
} }