Skip to content
Merged
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
12 changes: 12 additions & 0 deletions flight/net/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* - **secure** - Connection is secure
* - **accept** - HTTP accept parameters
* - **proxy_ip** - Proxy IP address of the client
* - **host** - The hostname from the request.
* - **servername** - The server's hostname. See `$_SERVER['SERVER_NAME']`.
*/
class Request
{
Expand Down Expand Up @@ -126,6 +128,15 @@ class Request
*/
public string $host;

/**
* Server name
*
* CAUTION: Note: Under Apache 2, UseCanonicalName = On and ServerName must be set.
* Otherwise, this value reflects the hostname supplied by the client, which can be spoofed.
* It is not safe to rely on this value in security-dependent contexts.
*/
public string $servername;

/**
* Stream path for where to pull the request body from
*/
Expand Down Expand Up @@ -164,6 +175,7 @@ public function __construct(array $config = [])
'accept' => self::getVar('HTTP_ACCEPT'),
'proxy_ip' => self::getProxyIpAddress(),
'host' => self::getVar('HTTP_HOST'),
'servername' => self::getVar('SERVER_NAME', ''),
];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected function setUp(): void
$_SERVER['REMOTE_ADDR'] = '8.8.8.8';
$_SERVER['HTTP_X_FORWARDED_FOR'] = '32.32.32.32';
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['SERVER_NAME'] = 'test.com';
$_SERVER['CONTENT_TYPE'] = '';

$_GET = [];
Expand Down Expand Up @@ -52,6 +53,7 @@ public function testDefaults(): void
$this->assertFalse($this->request->secure);
$this->assertEquals('', $this->request->accept);
$this->assertEquals('example.com', $this->request->host);
$this->assertEquals('test.com', $this->request->servername);
}

public function testIpAddress(): void
Expand Down