From d301d7a566fc4e8e65a855a483b1bd7727c05ff5 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 14 Feb 2008 05:32:46 +0000 Subject: [PATCH] Adding Flash client detection to RequestHandler git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6460 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/request_handler.php | 9 +++++++++ .../controller/components/request_handler.test.php | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 5e70d7207..e9f903107 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -238,6 +238,15 @@ class RequestHandlerComponent extends Object { function isAjax() { return env('HTTP_X_REQUESTED_WITH') === "XMLHttpRequest"; } +/** + * Returns true if the current HTTP request is coming from a Flash-based client + * + * @return boolean True if call is from Flash + * @access public + */ + function isFlash() { + return env('HTTP_USER_AGENT') === "Shockwave Flash"; + } /** * Returns true if the current request is over HTTPS, false otherwise. * 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 b00481a7c..74202b3ba 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -46,6 +46,18 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->assertTrue(in_array('Xml', $this->Controller->helpers)); } + function testRequestTypes() { + $this->assertFalse($this->RequestHandler->isFlash()); + $_SERVER['HTTP_USER_AGENT'] = 'Shockwave Flash'; + $this->assertTrue($this->RequestHandler->isFlash()); + unset($_SERVER['HTTP_USER_AGENT']); + + $this->assertFalse($this->RequestHandler->isAjax()); + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $this->assertTrue($this->RequestHandler->isAjax()); + unset($_SERVER['HTTP_X_REQUESTED_WITH']); + } + function tearDown() { unset($this->RequestHandler); unset($this->Controller);