Exemplo n.º 1
0
 public IISContextFactory(MemoryPool <byte> memoryPool, IHttpApplication <T> application, IISServerOptions options, IISHttpServer server)
 {
     _application = application;
     _memoryPool  = memoryPool;
     _options     = options;
     _server      = server;
 }
Exemplo n.º 2
0
        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);
            }
        }
 internal unsafe IISHttpContext(MemoryPool <byte> memoryPool, IntPtr pInProcessHandler, IISServerOptions options, IISHttpServer server)
     : base((HttpApiTypes.HTTP_REQUEST *)NativeMethods.HttpGetRawRequest(pInProcessHandler))
 {
     _memoryPool        = memoryPool;
     _pInProcessHandler = pInProcessHandler;
     _options           = options;
     _server            = server;
 }
Exemplo n.º 4
0
 public IISContextFactory(MemoryPool <byte> memoryPool, IHttpApplication <T> application, IISServerOptions options, IISHttpServer server, ILogger logger)
 {
     _application = application;
     _memoryPool  = memoryPool;
     _options     = options;
     _server      = server;
     _logger      = logger;
     AppContext.TryGetSwitch(Latin1Suppport, out _useLatin1);
 }
Exemplo n.º 5
0
        private static bool HandleShutdown(IntPtr pvRequestContext)
        {
            IISHttpServer server = null;

            try
            {
                server = (IISHttpServer)GCHandle.FromIntPtr(pvRequestContext).Target;
                server._applicationLifetime.StopApplication();
            }
            catch (Exception ex)
            {
                server?._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(HandleShutdown)}.");
            }
            return(true);
        }
Exemplo n.º 6
0
        internal unsafe IISHttpContext(
            MemoryPool <byte> memoryPool,
            IntPtr pInProcessHandler,
            IISServerOptions options,
            IISHttpServer server,
            ILogger logger)
            : base((HttpApiTypes.HTTP_REQUEST *)NativeMethods.HttpGetRawRequest(pInProcessHandler))
        {
            _memoryPool        = memoryPool;
            _pInProcessHandler = pInProcessHandler;
            _options           = options;
            _server            = server;
            _logger            = logger;

            ((IHttpBodyControlFeature)this).AllowSynchronousIO = _options.AllowSynchronousIO;
        }
Exemplo n.º 7
0
        private static void OnRequestsDrained(IntPtr serverContext)
        {
            IISHttpServer server = null;

            try
            {
                server = (IISHttpServer)GCHandle.FromIntPtr(serverContext).Target;

                server._nativeApplication.StopCallsIntoManaged();
                server._shutdownSignal.TrySetResult(null);
                server._cancellationTokenRegistration.Dispose();
            }
            catch (Exception ex)
            {
                server?._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(OnRequestsDrained)}.");
            }
        }
Exemplo n.º 8
0
        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;
                Interlocked.Increment(ref server._outstandingRequests);

                var context = server._iisContextFactory.CreateHttpContext(pInProcessHandler);

                ThreadPool.QueueUserWorkItem(state => _ = HandleRequest((IISHttpContext)state), context);
                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);
            }
        }
Exemplo n.º 9
0
        private static int HandleShutdown(IntPtr pvRequestContext)
        {
            IISHttpServer server = null;

            try
            {
                server = (IISHttpServer)GCHandle.FromIntPtr(pvRequestContext).Target;

                // server can be null if ungraceful shutdown.
                if (server == null)
                {
                    // return value isn't checked.
                    return(1);
                }

                server._applicationLifetime.StopApplication();
            }
            catch (Exception ex)
            {
                server?._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(HandleShutdown)}.");
            }
            return(1);
        }
Exemplo n.º 10
0
 public IISHttpContextOfT(MemoryPool <byte> memoryPool, IHttpApplication <TContext> application, IntPtr pInProcessHandler, IISServerOptions options, IISHttpServer server, ILogger logger)
     : base(memoryPool, pInProcessHandler, options, server, logger)
 {
     _application = application;
 }
Exemplo n.º 11
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;
 }