diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/NativeMethods.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/NativeMethods.cs index 4d718793d6..ad4142100a 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/NativeMethods.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/NativeMethods.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration internal static extern bool CloseHandle(IntPtr handle); public const int S_OK = 0; - private const string AspNetCoreModuleDll = "aspnetcore.dll"; + private const string AspNetCoreModuleDll = "aspnetcorerh.dll"; public enum REQUEST_NOTIFICATION_STATUS { @@ -32,47 +32,47 @@ namespace Microsoft.AspNetCore.Server.IISIntegration RQ_NOTIFICATION_FINISH_REQUEST } - public delegate REQUEST_NOTIFICATION_STATUS PFN_REQUEST_HANDLER(IntPtr pHttpContext, IntPtr pvRequestContext); + public delegate REQUEST_NOTIFICATION_STATUS PFN_REQUEST_HANDLER(IntPtr pInProcessHandler, IntPtr pvRequestContext); public delegate bool PFN_SHUTDOWN_HANDLER(IntPtr pvRequestContext); public delegate REQUEST_NOTIFICATION_STATUS PFN_ASYNC_COMPLETION(IntPtr pvManagedHttpContext, int hr, int bytes); - public delegate REQUEST_NOTIFICATION_STATUS PFN_WEBSOCKET_ASYNC_COMPLETION(IntPtr pHttpContext, IntPtr completionInfo, IntPtr pvCompletionContext); + public delegate REQUEST_NOTIFICATION_STATUS PFN_WEBSOCKET_ASYNC_COMPLETION(IntPtr pInProcessHandler, IntPtr completionInfo, IntPtr pvCompletionContext); // TODO make this all internal [DllImport(AspNetCoreModuleDll)] - public static extern int http_post_completion(IntPtr pHttpContext, int cbBytes); + public static extern int http_post_completion(IntPtr pInProcessHandler, int cbBytes); [DllImport(AspNetCoreModuleDll)] - public static extern int http_set_completion_status(IntPtr pHttpContext, REQUEST_NOTIFICATION_STATUS rquestNotificationStatus); + public static extern int http_set_completion_status(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS rquestNotificationStatus); [DllImport(AspNetCoreModuleDll)] - public static extern void http_indicate_completion(IntPtr pHttpContext, REQUEST_NOTIFICATION_STATUS notificationStatus); + public static extern void http_indicate_completion(IntPtr pInProcessHandler, REQUEST_NOTIFICATION_STATUS notificationStatus); [DllImport(AspNetCoreModuleDll)] public static extern void register_callbacks(PFN_REQUEST_HANDLER request_callback, PFN_SHUTDOWN_HANDLER shutdown_callback, PFN_ASYNC_COMPLETION managed_context_handler, IntPtr pvRequestContext, IntPtr pvShutdownContext); [DllImport(AspNetCoreModuleDll)] - internal unsafe static extern int http_write_response_bytes(IntPtr pHttpContext, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, out bool fCompletionExpected); + internal unsafe static extern int http_write_response_bytes(IntPtr pInProcessHandler, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, out bool fCompletionExpected); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern int http_flush_response_bytes(IntPtr pHttpContext, out bool fCompletionExpected); + public unsafe static extern int http_flush_response_bytes(IntPtr pInProcessHandler, out bool fCompletionExpected); [DllImport(AspNetCoreModuleDll)] - internal unsafe static extern HttpApiTypes.HTTP_REQUEST_V2* http_get_raw_request(IntPtr pHttpContext); + internal unsafe static extern HttpApiTypes.HTTP_REQUEST_V2* http_get_raw_request(IntPtr pInProcessHandler); [DllImport(AspNetCoreModuleDll)] - internal unsafe static extern HttpApiTypes.HTTP_RESPONSE_V2* http_get_raw_response(IntPtr pHttpContext); + internal unsafe static extern HttpApiTypes.HTTP_RESPONSE_V2* http_get_raw_response(IntPtr pInProcessHandler); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern void http_set_response_status_code(IntPtr pHttpContext, ushort statusCode, byte* pszReason); + public unsafe static extern void http_set_response_status_code(IntPtr pInProcessHandler, ushort statusCode, byte* pszReason); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern int http_read_request_bytes(IntPtr pHttpContext, byte* pvBuffer, int cbBuffer, out int dwBytesReceived, out bool fCompletionExpected); + public unsafe static extern int http_read_request_bytes(IntPtr pInProcessHandler, byte* pvBuffer, int cbBuffer, out int dwBytesReceived, out bool fCompletionExpected); [DllImport(AspNetCoreModuleDll)] public unsafe static extern bool http_get_completion_info(IntPtr pCompletionInfo, out int cbBytes, out int hr); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern bool http_set_managed_context(IntPtr pHttpContext, IntPtr pvManagedContext); + public unsafe static extern bool http_set_managed_context(IntPtr pInProcessHandler, IntPtr pvManagedContext); [DllImport(AspNetCoreModuleDll)] public unsafe static extern int http_get_application_properties(ref IISConfigurationData iiConfigData); @@ -81,10 +81,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration public unsafe static extern bool http_shutdown(); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern int http_websockets_read_bytes(IntPtr pHttpContext, byte* pvBuffer, int cbBuffer, PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback, IntPtr pvCompletionContext, out int dwBytesReceived, out bool fCompletionExpected); + public unsafe static extern int http_websockets_read_bytes(IntPtr pInProcessHandler, byte* pvBuffer, int cbBuffer, PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback, IntPtr pvCompletionContext, out int dwBytesReceived, out bool fCompletionExpected); [DllImport(AspNetCoreModuleDll)] - internal unsafe static extern int http_websockets_write_bytes(IntPtr pHttpContext, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback, IntPtr pvCompletionContext, out bool fCompletionExpected); + internal unsafe static extern int http_websockets_write_bytes(IntPtr pInProcessHandler, HttpApiTypes.HTTP_DATA_CHUNK* pDataChunks, int nChunks, PFN_WEBSOCKET_ASYNC_COMPLETION pfnCompletionCallback, IntPtr pvCompletionContext, out bool fCompletionExpected); [DllImport(AspNetCoreModuleDll)] public unsafe static extern int http_enable_websockets(IntPtr pHttpContext); @@ -93,13 +93,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration public unsafe static extern int http_cancel_io(IntPtr pHttpContext); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern int http_response_set_unknown_header(IntPtr pHttpContext, byte* pszHeaderName, byte* pszHeaderValue, ushort usHeaderValueLength, bool fReplace); + public unsafe static extern int http_response_set_unknown_header(IntPtr pInProcessHandler, byte* pszHeaderName, byte* pszHeaderValue, ushort usHeaderValueLength, bool fReplace); [DllImport(AspNetCoreModuleDll)] - internal unsafe static extern int http_response_set_known_header(IntPtr pHttpContext, int headerId, byte* pHeaderValue, ushort length, bool fReplace); + internal unsafe static extern int http_response_set_known_header(IntPtr pInProcessHandler, int headerId, byte* pHeaderValue, ushort length, bool fReplace); [DllImport(AspNetCoreModuleDll)] - public unsafe static extern int http_get_authentication_information(IntPtr pHttpContext, [MarshalAs(UnmanagedType.BStr)] out string authType, out IntPtr token); + public unsafe static extern int http_get_authentication_information(IntPtr pInProcessHandler, [MarshalAs(UnmanagedType.BStr)] out string authType, out IntPtr token); [DllImport("kernel32.dll")] public static extern IntPtr GetModuleHandle(string lpModuleName); diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.FeatureCollection.cs index 2c2c9ef5fe..bfb182ecfc 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.FeatureCollection.cs @@ -280,7 +280,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration StatusCode = StatusCodes.Status101SwitchingProtocols; ReasonPhrase = ReasonPhrases.GetReasonPhrase(StatusCodes.Status101SwitchingProtocols); await UpgradeAsync(); - NativeMethods.http_enable_websockets(_pHttpContext); + NativeMethods.http_enable_websockets(_pInProcessHandler); _wasUpgraded = true; _readWebSocketsOperation = new IISAwaitable(); diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs index 608aae0626..6b33a6d342 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration private static bool UpgradeAvailable = (Environment.OSVersion.Version >= new Version(6, 2)); - protected readonly IntPtr _pHttpContext; + protected readonly IntPtr _pInProcessHandler; private bool _wasUpgraded; private int _statusCode; @@ -63,15 +63,15 @@ namespace Microsoft.AspNetCore.Server.IISIntegration private const string NegotiateString = "Negotiate"; private const string BasicString = "Basic"; - internal unsafe IISHttpContext(MemoryPool memoryPool, IntPtr pHttpContext, IISOptions options) - : base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.http_get_raw_request(pHttpContext)) + internal unsafe IISHttpContext(MemoryPool memoryPool, IntPtr pInProcessHandler, IISOptions options) + : base((HttpApiTypes.HTTP_REQUEST*)NativeMethods.http_get_raw_request(pInProcessHandler)) { _thisHandle = GCHandle.Alloc(this); _memoryPool = memoryPool; - _pHttpContext = pHttpContext; + _pInProcessHandler = pInProcessHandler; - NativeMethods.http_set_managed_context(_pHttpContext, (IntPtr)_thisHandle); + NativeMethods.http_set_managed_context(pInProcessHandler, (IntPtr)_thisHandle); unsafe { Method = GetVerb(); @@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration unsafe { var hr = 0; - hr = NativeMethods.http_flush_response_bytes(_pHttpContext, out var fCompletionExpected); + hr = NativeMethods.http_flush_response_bytes(_pInProcessHandler, out var fCompletionExpected); if (!fCompletionExpected) { _operation.Complete(hr, 0); @@ -381,7 +381,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration fixed (byte* pReasonPhrase = reasonPhraseBytes) { // This copies data into the underlying buffer - NativeMethods.http_set_response_status_code(_pHttpContext, (ushort)StatusCode, pReasonPhrase); + NativeMethods.http_set_response_status_code(_pInProcessHandler, (ushort)StatusCode, pReasonPhrase); } HttpResponseHeaders.IsReadOnly = true; @@ -399,7 +399,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration { fixed (byte* pHeaderValue = headerValueBytes) { - NativeMethods.http_response_set_unknown_header(_pHttpContext, pHeaderName, pHeaderValue, (ushort)headerValueBytes.Length, fReplace: false); + NativeMethods.http_response_set_unknown_header(_pInProcessHandler, pHeaderName, pHeaderValue, (ushort)headerValueBytes.Length, fReplace: false); } } } @@ -411,7 +411,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration var headerValueBytes = Encoding.UTF8.GetBytes(headerValues[i]); fixed (byte* pHeaderValue = headerValueBytes) { - NativeMethods.http_response_set_known_header(_pHttpContext, knownHeaderIndex, pHeaderValue, (ushort)headerValueBytes.Length, fReplace: false); + NativeMethods.http_response_set_known_header(_pInProcessHandler, knownHeaderIndex, pHeaderValue, (ushort)headerValueBytes.Length, fReplace: false); } } } @@ -592,11 +592,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration chunk.fromMemory.BufferLength = (uint)buffer.Length; if (_wasUpgraded) { - hr = NativeMethods.http_websockets_write_bytes(_pHttpContext, pDataChunks, nChunks, IISAwaitable.WriteCallback, (IntPtr)_thisHandle, out fCompletionExpected); + hr = NativeMethods.http_websockets_write_bytes(_pInProcessHandler, pDataChunks, nChunks, IISAwaitable.WriteCallback, (IntPtr)_thisHandle, out fCompletionExpected); } else { - hr = NativeMethods.http_write_response_bytes(_pHttpContext, pDataChunks, nChunks, out fCompletionExpected); + hr = NativeMethods.http_write_response_bytes(_pInProcessHandler, pDataChunks, nChunks, out fCompletionExpected); } } } @@ -625,11 +625,11 @@ namespace Microsoft.AspNetCore.Server.IISIntegration } if (_wasUpgraded) { - hr = NativeMethods.http_websockets_write_bytes(_pHttpContext, pDataChunks, nChunks, IISAwaitable.WriteCallback, (IntPtr)_thisHandle, out fCompletionExpected); + hr = NativeMethods.http_websockets_write_bytes(_pInProcessHandler, pDataChunks, nChunks, IISAwaitable.WriteCallback, (IntPtr)_thisHandle, out fCompletionExpected); } else { - hr = NativeMethods.http_write_response_bytes(_pHttpContext, pDataChunks, nChunks, out fCompletionExpected); + hr = NativeMethods.http_write_response_bytes(_pInProcessHandler, pDataChunks, nChunks, out fCompletionExpected); } // Free the handles foreach (var handle in handles) @@ -659,7 +659,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration private unsafe IISAwaitable ReadAsync(int length) { var hr = NativeMethods.http_read_request_bytes( - _pHttpContext, + _pInProcessHandler, (byte*)_inputHandle.Pointer, length, out var dwReceivedBytes, @@ -677,7 +677,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration int dwReceivedBytes; bool fCompletionExpected; hr = NativeMethods.http_websockets_read_bytes( - _pHttpContext, + _pInProcessHandler, (byte*)_inputHandle.Pointer, length, IISAwaitable.ReadCallback, @@ -790,13 +790,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration { Debug.Assert(!_operation.HasContinuation, "Pending async operation!"); - var hr = NativeMethods.http_set_completion_status(_pHttpContext, requestNotificationStatus); + var hr = NativeMethods.http_set_completion_status(_pInProcessHandler, requestNotificationStatus); if (hr != NativeMethods.S_OK) { throw Marshal.GetExceptionForHR(hr); } - hr = NativeMethods.http_post_completion(_pHttpContext, 0); + hr = NativeMethods.http_post_completion(_pInProcessHandler, 0); if (hr != NativeMethods.S_OK) { throw Marshal.GetExceptionForHR(hr); @@ -805,7 +805,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration public void IndicateCompletion(NativeMethods.REQUEST_NOTIFICATION_STATUS notificationStatus) { - NativeMethods.http_indicate_completion(_pHttpContext, notificationStatus); + NativeMethods.http_indicate_completion(_pInProcessHandler, notificationStatus); } internal void OnAsyncCompletion(int hr, int cbBytes) @@ -873,7 +873,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration private WindowsPrincipal GetWindowsPrincipal() { - var hr = NativeMethods.http_get_authentication_information(_pHttpContext, out var authenticationType, out var token); + var hr = NativeMethods.http_get_authentication_information(_pInProcessHandler, out var authenticationType, out var token); if (hr == 0 && token != IntPtr.Zero && authenticationType != null) { diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs index 483ea3c163..19ea853197 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs @@ -14,8 +14,8 @@ namespace Microsoft.AspNetCore.Server.IISIntegration { private readonly IHttpApplication _application; - public IISHttpContextOfT(MemoryPool memoryPool, IHttpApplication application, IntPtr pHttpContext, IISOptions options) - : base(memoryPool, pHttpContext, options) + public IISHttpContextOfT(MemoryPool memoryPool, IHttpApplication application, IntPtr pInProcessHandler, IISOptions options) + : base(memoryPool, pInProcessHandler, options) { _application = application; } diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs index efd548c527..a6c43f4b6f 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs @@ -73,12 +73,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration _memoryPool.Dispose(); } - private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pHttpContext, IntPtr pvRequestContext) + private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pInProcessHandler, IntPtr pvRequestContext) { // Unwrap the server so we can create an http context and process the request var server = (IISHttpServer)GCHandle.FromIntPtr(pvRequestContext).Target; - var context = server._iisContextFactory.CreateHttpContext(pHttpContext); + var context = server._iisContextFactory.CreateHttpContext(pInProcessHandler); var task = context.ProcessRequestAsync(); @@ -136,9 +136,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration _options = options; } - public IISHttpContext CreateHttpContext(IntPtr pHttpContext) + public IISHttpContext CreateHttpContext(IntPtr pInProcessHandler) { - return new IISHttpContextOfT(_memoryPool, _application, pHttpContext, _options); + return new IISHttpContextOfT(_memoryPool, _application, pInProcessHandler, _options); } } } @@ -146,6 +146,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration // Over engineering to avoid allocations... internal interface IISContextFactory { - IISHttpContext CreateHttpContext(IntPtr pHttpContext); + IISHttpContext CreateHttpContext(IntPtr pInProcessHandler); } }