Skip to content
Snippets Groups Projects
Commit bcf37046 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #14458 from owncloud/revive/11157

Get the real protocol behind several proxies
parents af960781 9adcd15c
Branches
No related tags found
No related merge requests found
......@@ -480,8 +480,8 @@ class Request implements \ArrayAccess, \Countable, IRequest {
}
/**
* Returns the server protocol. It respects reverse proxy servers and load
* balancers.
* Returns the server protocol. It respects one or more reverse proxies servers
* and load balancers
* @return string Server protocol (http or https)
*/
public function getServerProtocol() {
......@@ -491,7 +491,13 @@ class Request implements \ArrayAccess, \Countable, IRequest {
}
if (isset($this->server['HTTP_X_FORWARDED_PROTO'])) {
if (strpos($this->server['HTTP_X_FORWARDED_PROTO'], ',') !== false) {
$parts = explode(',', $this->server['HTTP_X_FORWARDED_PROTO']);
$proto = strtolower(trim($parts[0]));
} else {
$proto = strtolower($this->server['HTTP_X_FORWARDED_PROTO']);
}
// Verify that the protocol is always HTTP or HTTPS
// default to http if an invalid value is provided
return $proto === 'https' ? 'https' : 'http';
......
......@@ -593,6 +593,27 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('http', $request->getServerProtocol());
}
public function testGetServerProtocolBehindLoadBalancers() {
$this->config
->expects($this->once())
->method('getSystemValue')
->with('overwriteprotocol')
->will($this->returnValue(''));
$request = new Request(
[
'server' => [
'HTTP_X_FORWARDED_PROTO' => 'https,http,http'
],
],
$this->secureRandom,
$this->config,
$this->stream
);
$this->assertSame('https', $request->getServerProtocol());
}
/**
* @dataProvider userAgentProvider
* @param string $testAgent
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment