aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-08-18 22:21:50 +0200
committerIgor Wiedler <igor@wiedler.ch>2011-08-18 22:26:30 +0200
commita48889fed83b007202e76ddf1ba5436eca310df0 (patch)
tree4036210bb9c7dfc3e029ae8ef6f1962b441be056
parent24e9fb24d105b8e475dbaf66fd99be2839b86675 (diff)
downloadforums-a48889fed83b007202e76ddf1ba5436eca310df0.tar
forums-a48889fed83b007202e76ddf1ba5436eca310df0.tar.gz
forums-a48889fed83b007202e76ddf1ba5436eca310df0.tar.bz2
forums-a48889fed83b007202e76ddf1ba5436eca310df0.tar.xz
forums-a48889fed83b007202e76ddf1ba5436eca310df0.zip
[feature/request-class] Add is_secure method to request for HTTPS
PHPBB3-9716
-rw-r--r--phpBB/includes/request/interface.php7
-rw-r--r--phpBB/includes/request/request.php10
-rw-r--r--tests/mock/request.php5
-rw-r--r--tests/request/request_test.php11
4 files changed, 33 insertions, 0 deletions
diff --git a/phpBB/includes/request/interface.php b/phpBB/includes/request/interface.php
index 983a05d6c4..c0b8768b24 100644
--- a/phpBB/includes/request/interface.php
+++ b/phpBB/includes/request/interface.php
@@ -122,6 +122,13 @@ interface phpbb_request_interface
public function is_ajax();
/**
+ * Checks if the current request is happening over HTTPS.
+ *
+ * @return bool True if the request is secure.
+ */
+ public function is_secure();
+
+ /**
* Returns all variable names for a given super global
*
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global
diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php
index 466397480b..8659ee8998 100644
--- a/phpBB/includes/request/request.php
+++ b/phpBB/includes/request/request.php
@@ -327,6 +327,16 @@ class phpbb_request implements phpbb_request_interface
}
/**
+ * Checks if the current request is happening over HTTPS.
+ *
+ * @return bool True if the request is secure.
+ */
+ public function is_secure()
+ {
+ return $this->server('HTTPS') == 'on';
+ }
+
+ /**
* Returns all variable names for a given super global
*
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global
diff --git a/tests/mock/request.php b/tests/mock/request.php
index 86b8695e32..18aa2e724c 100644
--- a/tests/mock/request.php
+++ b/tests/mock/request.php
@@ -57,6 +57,11 @@ class phpbb_mock_request implements phpbb_request_interface
return false;
}
+ public function is_secure()
+ {
+ return false;
+ }
+
public function variable_names($super_global = phpbb_request_interface::REQUEST)
{
return array_keys($this->data[$super_global]);
diff --git a/tests/request/request_test.php b/tests/request/request_test.php
index 24c9ae5112..2e56841601 100644
--- a/tests/request/request_test.php
+++ b/tests/request/request_test.php
@@ -117,6 +117,17 @@ class phpbb_request_test extends phpbb_test_case
$this->assertTrue($this->request->is_ajax());
}
+ public function test_is_secure()
+ {
+ $this->assertFalse($this->request->is_secure());
+
+ $this->request->enable_super_globals();
+ $_SERVER['HTTPS'] = 'on';
+ $this->request = new phpbb_request($this->type_cast_helper);
+
+ $this->assertTrue($this->request->is_secure());
+ }
+
public function test_variable_names()
{
$expected = array('test', 'unset');