From dedc85390c632eaec1cc22b5cb3336dc8c7b6bbd Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 29 Jun 2010 00:24:29 -0400 Subject: [PATCH] Adding header() to get header/server vars. Adding OPTIONS to the detector list. --- cake/libs/cake_request.php | 14 ++++++++++++++ cake/tests/cases/libs/cake_request.test.php | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/cake/libs/cake_request.php b/cake/libs/cake_request.php index 5c3315db1..7b075e784 100644 --- a/cake/libs/cake_request.php +++ b/cake/libs/cake_request.php @@ -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 * diff --git a/cake/tests/cases/libs/cake_request.test.php b/cake/tests/cases/libs/cake_request.test.php index 47eae44a6..d221a6f50 100644 --- a/cake/tests/cases/libs/cake_request.test.php +++ b/cake/tests/cases/libs/cake_request.test.php @@ -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() {