diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index e9f903107..cfc896d5d 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -505,7 +505,7 @@ class RequestHandlerComponent extends Object { function prefers($type = null) { $this->__initializeTypes(); if ($type == null) { - if (!empty($this->ext)) { + if (empty($this->ext)) { $accept = $this->accepts(null); if (is_array($accept)) { return $accept[0]; @@ -515,9 +515,10 @@ class RequestHandlerComponent extends Object { return $this->ext; } } - uses('set'); + App::import('Core', 'Set'); $types = Set::normalize($type, false); $accepts = array(); + foreach ($types as $type) { if ($this->accepts($type)) { $accepts[] = $type; diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index 74202b3ba..32eaf01f9 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -58,6 +58,18 @@ class RequestHandlerComponentTest extends CakeTestCase { unset($_SERVER['HTTP_X_REQUESTED_WITH']); } + function testClientPreference() { + $this->assertNotEqual($this->RequestHandler->prefers(), 'rss'); + $this->RequestHandler->ext = 'rss'; + $this->assertEqual($this->RequestHandler->prefers(), 'rss'); + + $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; + $_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'; + $this->RequestHandler = new RequestHandlerComponent(); + $this->assertEqual($this->RequestHandler->prefers(), 'xml'); + $_SERVER['HTTP_ACCEPT'] = $accept; + } + function tearDown() { unset($this->RequestHandler); unset($this->Controller);