private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pInProcessHandler, IntPtr pvRequestContext)
        {
            IISHttpServer server = null;

            try
            {
                // Unwrap the server so we can create an http context and process the request
                server = (IISHttpServer)GCHandle.FromIntPtr(pvRequestContext).Target;

                // server can be null if ungraceful shutdown.
                if (server == null)
                {
                    return(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST);
                }

                var safehandle = new NativeSafeHandle(pInProcessHandler);
                var context    = server._iisContextFactory.CreateHttpContext(safehandle);

                ThreadPool.UnsafeQueueUserWorkItem(context, preferLocal: false);

                return(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING);
            }
            catch (Exception ex)
            {
                server?._logger.LogError(0, ex, $"Unexpected exception in static {nameof(IISHttpServer)}.{nameof(HandleRequest)}.");

                return(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST);
            }
        }
        // TODO: Remove pInProcessHandler argument
        public bool IsWebSocketAvailable(NativeSafeHandle pInProcessHandler)
        {
            // Check if the Http upgrade feature is available in IIS.
            // To check this, we can look at the server variable WEBSOCKET_VERSION
            // And see if there is a version. Same check that Katana did:
            // https://github.com/aspnet/AspNetKatana/blob/9f6e09af6bf203744feb5347121fe25f6eec06d8/src/Microsoft.Owin.Host.SystemWeb/OwinAppContext.cs#L125
            // Actively not locking here as acquiring a lock on every request will hurt perf more than checking the
            // server variables a few extra times if a bunch of requests hit the server at the same time.
            if (!_websocketAvailable.HasValue)
            {
                _websocketAvailable = NativeMethods.HttpTryGetServerVariable(pInProcessHandler, WebSocketVersionString, out var webSocketsSupported) &&
                                      !string.IsNullOrEmpty(webSocketsSupported);
            }

            return(_websocketAvailable.Value);
        }
Exemple #3
0
        internal unsafe IISHttpContext(
            MemoryPool <byte> memoryPool,
            NativeSafeHandle pInProcessHandler,
            IISServerOptions options,
            IISHttpServer server,
            ILogger logger,
            bool useLatin1)
            : base((HttpApiTypes.HTTP_REQUEST *)NativeMethods.HttpGetRawRequest(pInProcessHandler), useLatin1: useLatin1)
        {
            _memoryPool          = memoryPool;
            _requestNativeHandle = pInProcessHandler;
            _options             = options;
            _server = server;
            _logger = logger;

            ((IHttpBodyControlFeature)this).AllowSynchronousIO = _options.AllowSynchronousIO;
        }
Exemple #4
0
 public IISNativeApplication(NativeSafeHandle nativeApplication)
 {
     _nativeApplication = nativeApplication;
 }
Exemple #5
0
 public IISHttpContextOfT(MemoryPool <byte> memoryPool, IHttpApplication <TContext> application, NativeSafeHandle pInProcessHandler, IISServerOptions options, IISHttpServer server, ILogger logger, bool useLatin1)
     : base(memoryPool, pInProcessHandler, options, server, logger, useLatin1)
 {
     _application = application;
 }
 public IISHttpContext CreateHttpContext(NativeSafeHandle pInProcessHandler)
 {
     return(new IISHttpContextOfT <T>(_memoryPool, _application, pInProcessHandler, _options, _server, _logger, _useLatin1));
 }