Add host to request

The requested host can be useful to build an url or route request based
on which host was used.
pull/398/head
Hugues Lismonde 6 years ago
parent c57ee8cb8d
commit b4c9c42b00
No known key found for this signature in database
GPG Key ID: 25DA81FF273A084C

@ -717,6 +717,7 @@ files - Uploaded files
secure - Whether the connection is secure
accept - HTTP accept parameters
proxy_ip - Proxy IP address of the client
host - The request host name
```
You can access the `query`, `data`, `cookies`, and `files` properties

@ -120,6 +120,11 @@ class Request {
*/
public $proxy_ip;
/**
* @var string HTTP host name
*/
public $host;
/**
* Constructor.
*
@ -145,7 +150,8 @@ class Request {
'files' => new Collection($_FILES),
'secure' => self::getVar('HTTPS', 'off') != 'off',
'accept' => self::getVar('HTTP_ACCEPT'),
'proxy_ip' => self::getProxyIpAddress()
'proxy_ip' => self::getProxyIpAddress(),
'host' => self::getVar('HTTP_HOST'),
);
}

@ -24,6 +24,7 @@ class RequestTest extends PHPUnit_Framework_TestCase
$_SERVER['REMOTE_ADDR'] = '8.8.8.8';
$_SERVER['HTTPS'] = 'on';
$_SERVER['HTTP_X_FORWARDED_FOR'] = '32.32.32.32';
$_SERVER['HTTP_HOST'] = 'example.com';
$this->request = new \flight\net\Request();
}
@ -39,6 +40,7 @@ class RequestTest extends PHPUnit_Framework_TestCase
$this->assertEquals(0, $this->request->length);
$this->assertEquals(true, $this->request->secure);
$this->assertEquals('', $this->request->accept);
$this->assertEquals('example.com', $this->request->host);
}
function testIpAddress() {

Loading…
Cancel
Save