Skip to content
Permalink
Browse files

Add ssl option.

  • Loading branch information...
markstory committed Apr 29, 2012
1 parent 9519ac9 commit 76d2075ffc137b882df833d61f4eab544dee4cae
Showing with 73 additions and 4 deletions.
  1. +8 −4 lib/Cake/Routing/Router.php
  2. +65 −0 lib/Cake/Test/TestCase/Routing/RouterTest.php
@@ -584,12 +584,12 @@ public static function promote($which = null) {
*
* There are a few 'special' parameters that can change the final URL string that is generated
*
* - `base` - Set to false to remove the base path from the generated url. If your application
* - `_base` - Set to false to remove the base path from the generated url. If your application
* is not in the root directory, this can be used to generate urls that are 'cake relative'.
* cake relative urls are required when using requestAction.
* - `?` - Takes an array of query string parameters. (Deprecated)
* - `_full` - If true the `FULL_BASE_URL` constant will be prepended to generated urls.
* - `#` - Allows you to set url hash fragments.
* - `full_base` - If true the `FULL_BASE_URL` constant will be prepended to generated urls.
* - `ssl` - Set to true to convert the generated url to https, or false to force http.
*
* @param string|array $url Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4"
* or an array specifying any of the following: 'controller', 'action',
@@ -623,7 +623,7 @@ public static function url($url = null, $full = false) {
$here = null;
}
$extension = $output = $q = $frag = null;
$extension = $output = $frag = null;
if (empty($url)) {
$output = isset($here) ? $here : '/';
@@ -650,6 +650,10 @@ public static function url($url = null, $full = false) {
$extension = '.' . $url['ext'];
unset($url['ext']);
}
if (isset($url['ssl'])) {
$url['_scheme'] = ($url['ssl'] == true) ? 'https' : 'http';
unset($url['ssl']);
}
// Copy the current action if the controller is the current one.
if (empty($url['action'])) {
@@ -1274,6 +1274,71 @@ public function testUrlGenerationWithAutoPrefixes() {
$this->assertEquals($expected, $result);
}
/**
* Test that the ssl option works.
*
* @return void
*/
public function testGenerationWithSslOption() {
Router::connect('/:controller/:action/*');
$_SERVER['HTTP_HOST'] = 'localhost';
$request = new Request();
Router::pushRequest(
$request->addParams(array(
'plugin' => null, 'controller' => 'images', 'action' => 'index'
))->addPaths(array(
'base' => '',
'here' => '/images/index',
'webroot' => '/',
))
);
$result = Router::url(array(
'ssl' => true
));
$this->assertEquals('https://localhost/images/index', $result);
$result = Router::url(array(
'ssl' => false
));
$this->assertEquals('http://localhost/images/index', $result);
}
/**
* Test ssl option when the current request is ssl.
*
* @return void
*/
public function testGenerateWithSslInSsl() {
Router::connect('/:controller/:action/*');
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'on';
$request = new Request();
Router::pushRequest(
$request->addParams(array(
'plugin' => null,
'controller' => 'images',
'action' => 'index'
))->addPaths(array(
'base' => '',
'here' => '/images/index',
'webroot' => '/',
))
);
$result = Router::url(array(
'ssl' => false
));
$this->assertEquals('http://localhost/images/index', $result);
$result = Router::url(array(
'ssl' => true
));
$this->assertEquals('https://localhost/images/index', $result);
}
/**
* test that auto-generated prefix routes persist
*

0 comments on commit 76d2075

Please sign in to comment.
You can’t perform that action at this time.