diff --git a/.travis.yml b/.travis.yml index e6a29c1..5640ad2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_script: # Install composer dependencies - composer validate - - composer require --no-update silverstripe/recipe-core 1.1.x-dev + - composer require --no-update silverstripe/recipe-core:1.1.x-dev silverstripe/versioned:1.1.x-dev - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: diff --git a/src/Control/InitialisationMiddleware.php b/src/Control/InitialisationMiddleware.php index c6304de..ce8877d 100644 --- a/src/Control/InitialisationMiddleware.php +++ b/src/Control/InitialisationMiddleware.php @@ -50,14 +50,14 @@ class InitialisationMiddleware implements HTTPMiddleware public function process(HTTPRequest $request, callable $delegate) { - $response = $delegate($request); - if ($this->config()->get('egress_proxy_default_enabled')) { $this->configureEgressProxy(); } - + $this->configureProxyDomainExclusions(); + $response = $delegate($request); + if ($this->config()->get('xss_protection_enabled') && $response) { $response->addHeader('X-XSS-Protection', '1; mode=block'); } @@ -80,8 +80,15 @@ protected function configureEgressProxy() $proxy = Environment::getEnv('SS_OUTBOUND_PROXY'); $proxyPort = Environment::getEnv('SS_OUTBOUND_PROXY_PORT'); - Environment::setEnv('http_proxy', $proxy . ':' . $proxyPort); - Environment::setEnv('https_proxy', $proxy . ':' . $proxyPort); + /* + * This sets the environment variables so they are available in + * external calls executed by exec() such as curl. + * Environment::setEnv() would only availabe in context of SilverStripe. + * Environment::getEnv() will fallback to getenv() and will therefore + * fetch the variables + */ + putenv('http_proxy=' . $proxy . ':' . $proxyPort); + putenv('https_proxy=' . $proxy . ':' . $proxyPort); } /** @@ -103,6 +110,10 @@ protected function configureProxyDomainExclusions() $noProxy = array_merge(explode(',', Environment::getEnv('NO_PROXY')), $noProxy); } - Environment::setEnv('NO_PROXY', implode(',', array_unique($noProxy))); + /* + * Set the environment varial for NO_PROXY the same way the + * proxy variables are set above + */ + putenv('NO_PROXY=' . implode(',', array_unique($noProxy))); } } diff --git a/tests/Control/InitialisationMiddlewareTest.php b/tests/Control/InitialisationMiddlewareTest.php index cdde8d4..43f81e7 100644 --- a/tests/Control/InitialisationMiddlewareTest.php +++ b/tests/Control/InitialisationMiddlewareTest.php @@ -31,7 +31,7 @@ protected function setUp() Environment::setEnv('SS_OUTBOUND_PROXY', ''); Environment::setEnv('SS_OUTBOUND_PROXY_PORT', ''); - Environment::setEnv('NO_PROXY', ''); + putenv('NO_PROXY='); } public function testDoNotConfigureProxyIfNoEnvironmentVarsAreSet() @@ -79,8 +79,7 @@ public function testConfigureEgressProxyDomainExclusions() 'example.com' ); - Environment::setEnv('NO_PROXY', 'foo.com,bar.com'); - + putenv('NO_PROXY=foo.com,bar.com'); $this->runMiddleware(); $this->assertSame(