diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea9683b..6039aeb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,30 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 1.8.7 - TBD + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- [#364](https://github.com/zendframework/zend-diactoros/issues/364) modifies detection of HTTPS schemas via the `$_SERVER['HTTPS']` value + such that an empty HTTPS-key will result in a scheme of `http` and not + `https`. + ## 1.8.6 - 2018-09-05 ### Added diff --git a/src/functions/marshal_uri_from_sapi.php b/src/functions/marshal_uri_from_sapi.php index decaafb8..eba3d1ec 100644 --- a/src/functions/marshal_uri_from_sapi.php +++ b/src/functions/marshal_uri_from_sapi.php @@ -171,7 +171,7 @@ function marshalUriFromSapi(array $server, array $headers) } else { $https = false; } - if (($https && 'off' !== strtolower($https)) + if (($https && 'on' === strtolower($https)) || strtolower($getHeaderFromArray('x-forwarded-proto', $headers, false)) === 'https' ) { $scheme = 'https'; diff --git a/test/ServerRequestFactoryTest.php b/test/ServerRequestFactoryTest.php index 003b8aec..fded011d 100644 --- a/test/ServerRequestFactoryTest.php +++ b/test/ServerRequestFactoryTest.php @@ -295,7 +295,7 @@ public function testMarshalUriDetectsHttpsSchemeFromServerValue($param) $request = $request->withHeader('Host', 'example.com'); $server = [ - $param => true, + $param => 'on', ]; $uri = marshalUriFromSapi($server, $request->getHeaders()); diff --git a/test/functions/MarshalUriFromSapiTest.php b/test/functions/MarshalUriFromSapiTest.php new file mode 100644 index 00000000..708522d3 --- /dev/null +++ b/test/functions/MarshalUriFromSapiTest.php @@ -0,0 +1,77 @@ + $httpsValue, + 'SERVER_NAME' => 'localhost', + 'SERVER_PORT' => '80', + 'SERVER_ADDR' => '172.22.0.4', + 'REMOTE_PORT' => '36852', + 'REMOTE_ADDR' => '172.22.0.1', + 'SERVER_SOFTWARE' => 'nginx/1.11.8', + 'GATEWAY_INTERFACE' => 'CGI/1.1', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + 'DOCUMENT_ROOT' => '/var/www/public', + 'DOCUMENT_URI' => '/index.php', + 'REQUEST_URI' => '/api/messagebox-schema', + 'PATH_TRANSLATED' => '/var/www/public', + 'PATH_INFO' => '', + 'SCRIPT_NAME' => '/index.php', + 'CONTENT_LENGTH' => '', + 'CONTENT_TYPE' => '', + 'REQUEST_METHOD' => 'GET', + 'QUERY_STRING' => '', + 'SCRIPT_FILENAME' => '/var/www/public/index.php', + 'FCGI_ROLE' => 'RESPONDER', + 'PHP_SELF' => '/index.php', + ]; + + $headers = [ + 'HTTP_COOKIE' => '', + 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7', + 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br', + 'HTTP_REFERER' => 'http://localhost:8080/index.html', + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)', + 'HTTP_ACCEPT' => 'application/json,*/*', + 'HTTP_CONNECTION' => 'keep-alive', + 'HTTP_HOST' => 'localhost:8080', + ]; + + $url = marshalUriFromSapi($server, $headers); + + self::assertSame($expectedScheme, $url->getScheme()); + } + + /** + * @return array + */ + public function returnsUrlWithCorrectHttpSchemeFromArraysProvider() + { + return [ + 'on-lowercase' => ['on', 'https'], + 'on-uppercase' => ['ON', 'https'], + 'off-lowercase' => ['off', 'http'], + 'off-mixed-case' => ['oFf', 'http'], + 'neither-on-nor-off' => ['foo', 'http'], + 'empty' => ['', 'http'], + ]; + } +}