Permalink
Browse files

Changes to Cake/Network/CakeRequest.php as discussed on Github for th…

…e detector code changes. Fixed the description of a few doc blocks, removed the use of getallheaders(), removed the failsafe (based on extension) for the xml and json detectors.
  • Loading branch information...
burzum committed Nov 22, 2014
1 parent 17e5d41 commit 83eb8ce7de46be59e4bd1e05f1e674ce1446454a
Showing with 6 additions and 9 deletions.
  1. +6 −9 lib/Cake/Network/CakeRequest.php
@@ -112,8 +112,8 @@ class CakeRequest implements ArrayAccess {
'webOS', 'Windows CE', 'Windows Phone OS', 'Xiino'
)),
'requested' => array('param' => 'requested', 'value' => 1),
'json' => array('header' => array('application/json'), 'param' => 'ext', 'value' => 'json'),
'xml' => array('header' => array('application/xml', 'text/xml'), 'param' => 'ext', 'value' => 'xml'),
'json' => array('header' => array('application/json')),
'xml' => array('header' => array('application/xml', 'text/xml')),
);
/**
@@ -524,9 +524,6 @@ public function getAcceptHeaders() {
$headers = array();
if (isset($_SERVER['HTTP_ACCEPT'])) {
$headers = explode(',', $_SERVER['HTTP_ACCEPT']);
} elseif (function_exists('getallheaders')) {
$headers = getallheaders();
$headers = explode(',', $headers['Accept']);
}
return $headers;
}
@@ -538,17 +535,17 @@ public function getAcceptHeaders() {
* @return bool Whether or not the request is the type you are checking.
*/
protected function _headerDetector($detect) {
$headers = $this->getAcceptHeaders();
$acceptHeaders = $this->getAcceptHeaders();
foreach ($detect['header'] as $header) {
if (in_array($header, $headers)) {
if (in_array($header, $acceptHeaders)) {
return true;
}
}
return false;
}
/**
* Detects if a specific header is present
* Detects if a specific request parameter is present.
*
* @param array $detect Detector options array.
* @return bool Whether or not the request is the type you are checking.
@@ -566,7 +563,7 @@ protected function _paramDetector($detect) {
}
/**
* Detects if a specific header is present
* Detects if a specific environment variable is present.
*
* @param array $detect Detector options array.
* @return bool Whether or not the request is the type you are checking.

0 comments on commit 83eb8ce

Please sign in to comment.