private static PipelineHandler Sut(params Type[] handlers)
        {
            var handlerCollection = new HandlersCollection(handlers);
            var configValues      = handlerCollection.Keys.Select((x, i) => ($"{i}:handler", x)).ToArray();
            var config            = new InMemoryConfiguration("pipeline", configValues);

            return(new PipelineHandler(config, handlerCollection.HandlerProvider));
        }
        public async Task ThrowOnUnknownHandler()
        {
            var handlers = new HandlersCollection(typeof(TestHandler1));
            var config   = new InMemoryConfiguration("pipeline", ("0:handler", "unknown"));
            var sut      = new PipelineHandler(config, handlers.HandlerProvider);

            await Assert.ThrowsAsync <HandlerNotFoundException>(() => sut.HandleAsync(RouteContext));
        }
        public void CanDisablePipelineStep()
        {
            var handlers = new HandlersCollection(typeof(TestHandler1), typeof(TestHandler2));
            var config   = new InMemoryConfiguration("pipeline",
                                                     ("0:handler", "test1"),
                                                     ("1:disable", "true"),
                                                     ("1:handler", "test2"));
            var sut = new PipelineHandler(config, handlers.HandlerProvider);

            var expected = TestHandler1.Response;

            var actual = sut.HandleAsync(RouteContext).Result;

            DeepAssert.Equal(expected, actual);
        }
示例#4
0
        private void Initialize()
        {
            if (!IsFastCgiInstalled())
            {
                // If FastCGI is not installed on IIS then bail out as there is no point to continue
                _registrationType = PHPRegistrationType.NoneNoFastCgi;
                return;
            }

            // Get the handlers collection
            var handlersSection = _configurationWrapper.GetHandlersSection();
            _handlersCollection = handlersSection.Handlers;

            // Get the Default document collection
            var defaultDocumentSection = _configurationWrapper.GetDefaultDocumentSection();
            _defaultDocumentCollection = defaultDocumentSection.Files;

            // Get the FastCgi application collection
            var appHostConfig = _configurationWrapper.GetAppHostConfiguration();
            var fastCgiSection = (FastCgiSection)appHostConfig.GetSection("system.webServer/fastCgi", typeof(FastCgiSection));
            _fastCgiApplicationCollection = fastCgiSection.Applications;

            // Assume by default that PHP is not registered
            _registrationType = PHPRegistrationType.None;

            // Find the currently active PHP handler and FastCGI application
            var handler = _handlersCollection.GetActiveHandler("*.php");
            if (handler != null)
            {
                if (String.Equals(handler.Modules, "FastCgiModule", StringComparison.OrdinalIgnoreCase))
                {
                    _registrationType = PHPRegistrationType.FastCgi;
                }
                else if (String.Equals(handler.Modules, "CgiModule", StringComparison.OrdinalIgnoreCase))
                {
                    _registrationType = PHPRegistrationType.Cgi;
                }
                else if (String.Equals(handler.Modules, "IsapiModule", StringComparison.OrdinalIgnoreCase))
                {
                    _registrationType = PHPRegistrationType.Isapi;
                }

                if (_registrationType == PHPRegistrationType.FastCgi)
                {
                    ApplicationElement fastCgiApplication = _fastCgiApplicationCollection.GetApplication(handler.Executable, handler.Arguments);
                    if (fastCgiApplication != null)
                    {
                        _currentPhpHandler = handler;
                        _currentFastCgiApplication = fastCgiApplication;
                        _phpIniFilePath = GetPHPIniFilePath();
                        if (String.IsNullOrEmpty(_phpIniFilePath))
                        {
                            throw new FileNotFoundException(String.Format(Resources.CannotFindPhpIniForExecutableError, handler.Executable));
                        }
                        _phpDirectory = GetPHPDirectory();
                    }
                    else
                    {
                        _registrationType = PHPRegistrationType.None;
                    }
                }
            }
        }
示例#5
0
        private static string GenerateHandlerName(HandlersCollection collection, string phpVersion)
        {
            string prefix = String.Format("php-{0}",phpVersion);
            string name = prefix;

            for (var i = 1;; i++)
            {
                if (collection[name] != null)
                {
                    name = String.Format("{0}_{1}", prefix, i.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    break;
                }
            }
            return name;
        }
示例#6
0
        private void Initialize()
        {
            // Get the handlers collection
            ManagementConfiguration config = _managementUnit.Configuration;
            HandlersSection handlersSection = (HandlersSection)config.GetSection("system.webServer/handlers", typeof(HandlersSection));
            _handlersCollection = handlersSection.Handlers;

            // Get the Default document collection
            DefaultDocumentSection defaultDocumentSection = (DefaultDocumentSection)config.GetSection("system.webServer/defaultDocument", typeof(DefaultDocumentSection));
            _defaultDocumentCollection = defaultDocumentSection.Files;

            // Get the FastCgi application collection
            Configuration appHostConfig = _managementUnit.ServerManager.GetApplicationHostConfiguration();
            FastCgiSection fastCgiSection = (FastCgiSection)appHostConfig.GetSection("system.webServer/fastCgi", typeof(FastCgiSection));
            _fastCgiApplicationCollection = fastCgiSection.Applications;

            // Assume by default that PHP is not registered
            _registrationType = PHPRegistrationType.None;

            // Find the currently active PHP handler and FastCGI application
            HandlerElement handler = _handlersCollection.GetActiveHandler("*.php");
            if (handler != null)
            {
                if (String.Equals(handler.Modules, "FastCgiModule", StringComparison.OrdinalIgnoreCase))
                {
                    _registrationType = PHPRegistrationType.FastCgi;
                }
                else if (String.Equals(handler.Modules, "CgiModule", StringComparison.OrdinalIgnoreCase))
                {
                    _registrationType = PHPRegistrationType.Cgi;
                }
                else if (String.Equals(handler.Modules, "IsapiModule", StringComparison.OrdinalIgnoreCase))
                {
                    _registrationType = PHPRegistrationType.Isapi;
                }

                if (_registrationType == PHPRegistrationType.FastCgi)
                {
                    ApplicationElement fastCgiApplication = _fastCgiApplicationCollection.GetApplication(handler.Executable, handler.Arguments);
                    if (fastCgiApplication != null)
                    {
                        _currentPHPHandler = handler;
                        _currentFastCgiApplication = fastCgiApplication;
                        _phpIniFilePath = GetPHPIniFilePath();
                        _phpDirectory = GetPHPDirectory();
                    }
                    else
                    {
                        _registrationType = PHPRegistrationType.None;
                    }
                }
            }
        }
示例#7
0
        private static string GenerateHandlerName(HandlersCollection collection, string phpVersion)
        {
            string prefix = "php-" + phpVersion;
            string name = prefix;

            for (int i = 1; true; i++)
            {
                if (collection[name] != null)
                {
                    name = prefix + "_" + i.ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    break;
                }
            }
            return name;
        }
示例#8
0
 private static void MoveHandlerOnTop(HandlersCollection handlersCollection, string handlerName)
 {
     HandlerElement handlerElement = handlersCollection[handlerName];
     if (handlerElement != null)
     {
         handlersCollection.Remove(handlerElement);
         handlersCollection.AddCopyAt(0, handlerElement);
     }
 }
示例#9
0
        private void Initialize()
        {
            // Get the handlers collection
            ManagementConfiguration config = _managementUnit.Configuration;
            HandlersSection handlersSection = (HandlersSection)config.GetSection("system.webServer/handlers", typeof(HandlersSection));
            _handlersCollection = handlersSection.Handlers;

            // Get the FastCgi application collection
            Configuration appHostConfig = _managementUnit.ServerManager.GetApplicationHostConfiguration();
            FastCgiSection fastCgiSection = (FastCgiSection)appHostConfig.GetSection("system.webServer/fastCgi", typeof(FastCgiSection));
            _fastCgiApplicationCollection = fastCgiSection.Applications;

            // Find the currently active PHP handler and FastCGI application
            HandlerElement handler = _handlersCollection.GetActiveHandler("*.php");
            if (handler != null)
            {
                string executable = handler.ScriptProcessor;
                
                ApplicationElement fastCgiApplication = _fastCgiApplicationCollection.GetApplication(executable, "");
                if (fastCgiApplication != null)
                {
                    _currentPHPHandler = handler;
                    _currentFastCgiApplication = fastCgiApplication;
                }
            }
        }