mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding header() to get header/server vars.
Adding OPTIONS to the detector list.
This commit is contained in:
parent
3e6cd0be44
commit
dedc85390c
2 changed files with 26 additions and 1 deletions
|
@ -86,6 +86,7 @@ class CakeRequest implements ArrayAccess {
|
|||
'put' => array('env' => 'REQUEST_METHOD', 'value' => 'PUT'),
|
||||
'delete' => array('env' => 'REQUEST_METHOD', 'value' => 'DELETE'),
|
||||
'head' => array('env' => 'REQUEST_METHOD', 'value' => 'HEAD'),
|
||||
'options' => array('env' => 'REQUEST_METHOD', 'value' => 'OPTIONS'),
|
||||
'ssl' => array('env' => 'HTTPS', 'value' => 1),
|
||||
'ajax' => array('env' => 'HTTP_X_REQUESTED_WITH', 'value' => 'XMLHttpRequest'),
|
||||
'flash' => array('env' => 'HTTP_USER_AGENT', 'pattern' => '/^(Shockwave|Adobe) Flash/'),
|
||||
|
@ -531,6 +532,19 @@ class CakeRequest implements ArrayAccess {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a header from the Request information.
|
||||
*
|
||||
* @param string $name Name of the header you want.
|
||||
* @return mixed Either false on no header being set or the value of the header.
|
||||
*/
|
||||
public function header($name) {
|
||||
$name = 'HTTP_' . strtoupper(str_replace('-', '_', $name));
|
||||
if (!empty($_SERVER[$name])) {
|
||||
return $_SERVER[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Array access read implementation
|
||||
*
|
||||
|
|
|
@ -656,6 +656,18 @@ class CakeRequestTestCase extends CakeTestCase {
|
|||
return $request->return == true;
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting headers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testHeader() {
|
||||
$request = new CakeRequest('/', false);
|
||||
|
||||
$this->assertEquals($_SERVER['HTTP_HOST'], $request->header('host'));
|
||||
$this->assertEquals($_SERVER['HTTP_USER_AGENT'], $request->header('User-Agent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testBaseUrlAndWebrootWithModRewrite method
|
||||
*
|
||||
|
@ -727,7 +739,6 @@ class CakeRequestTestCase extends CakeTestCase {
|
|||
/**
|
||||
* testBaseUrlwithModRewriteAlias method
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBaseUrlwithModRewriteAlias() {
|
||||
|
|
Loading…
Add table
Reference in a new issue