Merge pull request #398 from hlidotbe/feature/request-host

Add host to request
pull/405/head
Mike Cao 6 years ago committed by GitHub
commit da8eaefc63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

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

Loading…
Cancel
Save