diff --git a/CHANGELOG.md b/CHANGELOG.md index c38a6c2..3b289ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 0.4.1 + +### Fixed + +- Support for ´HTTP_X_FORWARDED_PROTO´ + ## 0.4.0 ### Fixed diff --git a/src/ServerRequestCreator.php b/src/ServerRequestCreator.php index 29922b2..1e66daa 100644 --- a/src/ServerRequestCreator.php +++ b/src/ServerRequestCreator.php @@ -242,14 +242,18 @@ private function createUriFromArray(array $server): UriInterface { $uri = $this->uriFactory->createUri(''); - if (isset($server['REQUEST_SCHEME'])) { - $uri = $uri->withScheme($server['REQUEST_SCHEME']); - } elseif (isset($server['HTTPS'])) { - $uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http'); - } + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { + $uri = $uri->withScheme($server['HTTP_X_FORWARDED_PROTO']); + } else { + if (isset($server['REQUEST_SCHEME'])) { + $uri = $uri->withScheme($server['REQUEST_SCHEME']); + } elseif (isset($server['HTTPS'])) { + $uri = $uri->withScheme('on' === $server['HTTPS'] ? 'https' : 'http'); + } - if (isset($server['SERVER_PORT'])) { - $uri = $uri->withPort($server['SERVER_PORT']); + if (isset($server['SERVER_PORT'])) { + $uri = $uri->withPort($server['SERVER_PORT']); + } } if (isset($server['HTTP_HOST'])) { diff --git a/tests/ServerRequestCreatorTest.php b/tests/ServerRequestCreatorTest.php index 0addd9b..b93a8a6 100644 --- a/tests/ServerRequestCreatorTest.php +++ b/tests/ServerRequestCreatorTest.php @@ -448,6 +448,10 @@ public function dataGetUriFromGlobals() 'https://www.blakesimpson.co.uk/blog/article.php?id=10&user=foo', array_merge($server, ['HTTPS' => 'on', 'SERVER_PORT' => '443']), ], + 'Secure request via proxy' => [ + 'https://www.blakesimpson.co.uk/blog/article.php?id=10&user=foo', + array_merge($server, ['HTTP_X_FORWARDED_PROTO' => 'https', 'SERVER_PORT' => '80']), + ], 'HTTP_HOST missing' => [ 'http://www.blakesimpson.co.uk/blog/article.php?id=10&user=foo', array_merge($server, ['HTTP_HOST' => null]),