Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 97bfc56

Browse files
committed
Merge branch 'hotfix/364' into release-1.8
Close #364 Backport #363
2 parents 1dc4959 + 07cd173 commit 97bfc56

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 1.8.7 - TBD
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- Nothing.
14+
15+
### Deprecated
16+
17+
- Nothing.
18+
19+
### Removed
20+
21+
- Nothing.
22+
23+
### Fixed
24+
25+
- [#364](https://github.com/zendframework/zend-diactoros/issues/364) modifies detection of HTTPS schemas via the `$_SERVER['HTTPS']` value
26+
such that an empty HTTPS-key will result in a scheme of `http` and not
27+
`https`.
28+
529
## 1.8.6 - 2018-09-05
630

731
### Added

src/functions/marshal_uri_from_sapi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function marshalUriFromSapi(array $server, array $headers)
171171
} else {
172172
$https = false;
173173
}
174-
if (($https && 'off' !== strtolower($https))
174+
if (($https && 'on' === strtolower($https))
175175
|| strtolower($getHeaderFromArray('x-forwarded-proto', $headers, false)) === 'https'
176176
) {
177177
$scheme = 'https';

test/ServerRequestFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function testMarshalUriDetectsHttpsSchemeFromServerValue($param)
295295
$request = $request->withHeader('Host', 'example.com');
296296

297297
$server = [
298-
$param => true,
298+
$param => 'on',
299299
];
300300

301301
$uri = marshalUriFromSapi($server, $request->getHeaders());
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
4+
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace ZendTest\Diactoros\functions;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use function Zend\Diactoros\marshalUriFromSapi;
12+
13+
class MarshalUriFromSapiTest extends TestCase
14+
{
15+
/**
16+
* @param string $httpsValue
17+
* @param string $expectedScheme
18+
* @dataProvider returnsUrlWithCorrectHttpSchemeFromArraysProvider
19+
*/
20+
public function testReturnsUrlWithCorrectHttpSchemeFromArrays($httpsValue, $expectedScheme)
21+
{
22+
$server = [
23+
'HTTPS' => $httpsValue,
24+
'SERVER_NAME' => 'localhost',
25+
'SERVER_PORT' => '80',
26+
'SERVER_ADDR' => '172.22.0.4',
27+
'REMOTE_PORT' => '36852',
28+
'REMOTE_ADDR' => '172.22.0.1',
29+
'SERVER_SOFTWARE' => 'nginx/1.11.8',
30+
'GATEWAY_INTERFACE' => 'CGI/1.1',
31+
'SERVER_PROTOCOL' => 'HTTP/1.1',
32+
'DOCUMENT_ROOT' => '/var/www/public',
33+
'DOCUMENT_URI' => '/index.php',
34+
'REQUEST_URI' => '/api/messagebox-schema',
35+
'PATH_TRANSLATED' => '/var/www/public',
36+
'PATH_INFO' => '',
37+
'SCRIPT_NAME' => '/index.php',
38+
'CONTENT_LENGTH' => '',
39+
'CONTENT_TYPE' => '',
40+
'REQUEST_METHOD' => 'GET',
41+
'QUERY_STRING' => '',
42+
'SCRIPT_FILENAME' => '/var/www/public/index.php',
43+
'FCGI_ROLE' => 'RESPONDER',
44+
'PHP_SELF' => '/index.php',
45+
];
46+
47+
$headers = [
48+
'HTTP_COOKIE' => '',
49+
'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7',
50+
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br',
51+
'HTTP_REFERER' => 'http://localhost:8080/index.html',
52+
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)',
53+
'HTTP_ACCEPT' => 'application/json,*/*',
54+
'HTTP_CONNECTION' => 'keep-alive',
55+
'HTTP_HOST' => 'localhost:8080',
56+
];
57+
58+
$url = marshalUriFromSapi($server, $headers);
59+
60+
self::assertSame($expectedScheme, $url->getScheme());
61+
}
62+
63+
/**
64+
* @return array
65+
*/
66+
public function returnsUrlWithCorrectHttpSchemeFromArraysProvider()
67+
{
68+
return [
69+
'on-lowercase' => ['on', 'https'],
70+
'on-uppercase' => ['ON', 'https'],
71+
'off-lowercase' => ['off', 'http'],
72+
'off-mixed-case' => ['oFf', 'http'],
73+
'neither-on-nor-off' => ['foo', 'http'],
74+
'empty' => ['', 'http'],
75+
];
76+
}
77+
}

0 commit comments

Comments
 (0)