Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Control/Middleware/HTTPCacheControlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function process(HTTPRequest $request, callable $delegate)
* @var array
*/
private static $defaultVary = [
"X-Forwarded-Protocol" => true,
'X-Forwarded-Proto' => true,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Middleware/TrustedProxyMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class TrustedProxyMiddleware implements HTTPMiddleware
* @var array
*/
private $proxySchemeHeaders = [
'X-Forwarded-Protocol',
'X-Forwarded-Proto',
'X-Forwarded-Protocol',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep both here instead of just the modern version? I assume this is what you mean by "incoming headers" in the PR description but I didn't see the reason for keeping it in the description.

];

/**
Expand Down
46 changes: 44 additions & 2 deletions tests/php/Control/DirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,14 @@ public function testIsHttps()

// nothing available
$headers = [
'HTTP_X_FORWARDED_PROTOCOL', 'HTTPS', 'SSL'
'HTTP_X_FORWARDED_PROTOCOL',
'HTTP_X_FORWARDED_PROTO',
'HTTPS',
'SSL',
];
foreach ($headers as $header) {
if (isset($_SERVER[$header])) {
unset($_SERVER['HTTP_X_FORWARDED_PROTOCOL']);
unset($_SERVER[$header]);
}
}

Expand All @@ -813,6 +816,45 @@ public function testIsHttps()
Director::test('TestController/returnIsSSL')->getBody()
);

$this->assertEquals(
'yes',
Director::test(
'TestController/returnIsSSL',
null,
null,
null,
null,
['X-Forwarded-Proto' => 'https']
)->getBody()
);

$this->assertEquals(
'no',
Director::test(
'TestController/returnIsSSL',
null,
null,
null,
null,
['X-Forwarded-Proto' => 'http']
)->getBody()
);

$this->assertEquals(
'yes',
Director::test(
'TestController/returnIsSSL',
null,
null,
null,
null,
[
'X-Forwarded-Proto' => 'https',
'X-Forwarded-Protocol' => 'http',
]
)->getBody()
);

$this->assertEquals(
'yes',
Director::test(
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Control/HTTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public function testConfigVary()
$response = new HTTPResponse($body, 200);
HTTPCacheControlMiddleware::singleton()
->setMaxAge(30)
->setVary('X-Requested-With, X-Forwarded-Protocol');
->setVary('X-Requested-With, X-Forwarded-Proto');
$this->addCacheHeaders($response);

// Vary set properly
$v = $response->getHeader('Vary');
$this->assertStringContainsString("X-Forwarded-Protocol", $v);
$this->assertStringContainsString("X-Forwarded-Proto", $v);
$this->assertStringContainsString("X-Requested-With", $v);
$this->assertStringNotContainsString("Cookie", $v);
$this->assertStringNotContainsString("User-Agent", $v);
Expand Down
23 changes: 23 additions & 0 deletions tests/php/Control/Middleware/HTTPCacheControlMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ protected function setUp(): void
HTTPCacheControlMiddleware::reset();
}

public function testDefaultVaryIsXForwardedProto()
{
$cc = HTTPCacheControlMiddleware::singleton();
$response = new HTTPResponse();
$cc->applyToResponse($response);
$vary = $response->getHeader('Vary');
$this->assertNotEmpty($vary);
$this->assertStringContainsString('X-Forwarded-Proto', $vary);
$this->assertStringNotContainsString('X-Forwarded-Protocol', $vary);
}

public function testDefaultVaryCanBeDisabledViaConfig()
{
HTTPCacheControlMiddleware::config()->set('defaultVary', []);
HTTPCacheControlMiddleware::reset();

$cc = HTTPCacheControlMiddleware::singleton();
$response = new HTTPResponse();
$cc->applyToResponse($response);

$this->assertEmpty($response->getHeader('Vary'));
}

public function provideCacheStates()
{
return [
Expand Down