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
This commit is contained in:
nate 2008-02-14 05:32:46 +00:00
parent 5e8a2fb7f4
commit d301d7a566
2 changed files with 21 additions and 0 deletions

View file

@ -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.
*

View file

@ -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);