Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Merge pull request #1300 from realityking/webclient
Browse files Browse the repository at this point in the history
Reduce the use of JBrowser.
  • Loading branch information
chdemko committed Jun 29, 2012
2 parents d732b3b + 352f90a commit e4bda8f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 66 deletions.
25 changes: 12 additions & 13 deletions libraries/joomla/application/web.php
Expand Up @@ -520,19 +520,6 @@ public function redirect($url, $moved = false)

echo $html;
}
/*
* For WebKit based browsers do not send a 303, as it causes subresource reloading. You can view the
* bug report at: https://bugs.webkit.org/show_bug.cgi?id=38690
*/
elseif (!$moved && ($this->client->engine == JApplicationWebClient::WEBKIT))
{
$html = '<html><head>';
$html .= '<meta http-equiv="refresh" content="0; url=' . $url . '" />';
$html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->charSet . '" />';
$html .= '</head><body></body></html>';

echo $html;
}
else
{
// All other cases use the more efficient HTTP header for redirection.
Expand Down Expand Up @@ -964,6 +951,18 @@ protected function header($string, $replace = true, $code = null)
header($string, $replace, $code);
}

/**
* Determine if we are using a secure (SSL) connection.
*
* @return boolean True if using SSL, false if not.
*
* @since 12.2
*/
public function isSSLConnection()
{
return ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || getenv('SSL_PROTOCOL_VERSION'));
}

/**
* Allows the application to load a custom or default document.
*
Expand Down
6 changes: 3 additions & 3 deletions libraries/joomla/application/web/client.php
Expand Up @@ -129,9 +129,9 @@ class JApplicationWebClient
/**
* Class constructor.
*
* @param mixed $userAgent The optional user-agent string to parse.
* @param mixed $acceptEncoding The optional client accept encoding string to parse.
* @param mixed $acceptLanguage The optional client accept language string to parse.
* @param string $userAgent The optional user-agent string to parse.
* @param string $acceptEncoding The optional client accept encoding string to parse.
* @param string $acceptLanguage The optional client accept language string to parse.
*
* @since 12.1
*/
Expand Down
6 changes: 4 additions & 2 deletions libraries/joomla/environment/browser.php
Expand Up @@ -21,11 +21,9 @@
* @package Joomla.Platform
* @subpackage Environment
* @since 11.1
* @deprecated This API may be changed in the near future and should not be considered stable
*/
class JBrowser
{

/**
* @var integer Major version number
* @since 12.1
Expand Down Expand Up @@ -653,9 +651,13 @@ public function isMobile()
* @return boolean True if using SSL, false if not.
*
* @since 11.1
* @deprecated 13.3 Use the isSSLConnection method on the application object.
*/
public function isSSLConnection()
{
JLog::add('JBrowser::isSSLConnection() is deprecated. Use the isSSLConnection method on the application object instead.',
JLog::WARNING, 'deprecated');

return ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || getenv('SSL_PROTOCOL_VERSION'));
}
}
29 changes: 24 additions & 5 deletions libraries/legacy/application/application.php
Expand Up @@ -72,6 +72,12 @@ class JApplication extends JApplicationBase
*/
public $startTime = null;

/**
* @var JApplicationWebClient The application client object.
* @since 12.2
*/
public $client;

/**
* @var array JApplication instances container.
* @since 11.3
Expand Down Expand Up @@ -106,6 +112,10 @@ public function __construct($config = array())
// Create the input object
$this->input = new JInput;

$this->client = new JApplicationWebClient;

$this->loadDispatcher();

// Set the session default name.
if (!isset($config['session_name']))
{
Expand All @@ -130,8 +140,6 @@ public function __construct($config = array())
$this->_createSession(self::getHash($config['session_name']));
}

$this->loadDispatcher();

$this->requestTime = gmdate('Y-m-d H:i');

// Used by task system to ensure that the system doesn't go over time.
Expand Down Expand Up @@ -385,10 +393,9 @@ public function redirect($url, $msg = '', $msgType = 'message', $moved = false)
else
{
$document = JFactory::getDocument();
jimport('joomla.environment.browser');
$navigator = JBrowser::getInstance();

jimport('phputf8.utils.ascii');
if ($navigator->isBrowser('msie') && !utf8_is_ascii($url))
if (($this->client->engine == JApplicationWebClient::TRIDENT) && !utf8_is_ascii($url))
{
// MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />'
Expand Down Expand Up @@ -1110,6 +1117,18 @@ public static function isWinOS()
return IS_WIN;
}

/**
* Determine if we are using a secure (SSL) connection.
*
* @return boolean True if using SSL, false if not.
*
* @since 12.2
*/
public function isSSLConnection()
{
return ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || getenv('SSL_PROTOCOL_VERSION'));
}

/**
* Returns the response as a string.
*
Expand Down
40 changes: 37 additions & 3 deletions tests/suites/legacy/application/JApplicationTest.php
Expand Up @@ -13,6 +13,15 @@
*/
class JApplicationTest extends PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new JApplication(array('session' => false));
}

/**
* @todo Implement testGetInstance().
*/
Expand All @@ -35,14 +44,19 @@ public function testInitialise()
* @todo Implement testInitialise().
* @cover JApplication::__construct
*/
public function testConstructJInput()
public function testConstruct()
{
$app = new JApplication(array('session' => false));
$this->assertThat(
$app->input,
$this->object->input,
$this->isInstanceOf('JInput'),
__LINE__ . 'JApplication->input not initialized properly'
);

$this->assertInstanceOf(
'JApplicationWebClient',
$this->object->client,
'Client property wrong type'
);
}

/**
Expand Down Expand Up @@ -301,4 +315,24 @@ public function testIsWinOS()
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @covers JApplication::isSSLConnection
*/
public function testIsSSLConnection()
{
unset($_SERVER['HTTPS']);

$this->assertThat(
$this->object->isSSLConnection(),
$this->equalTo(false)
);

$_SERVER['HTTPS'] = 'on';

$this->assertThat(
$this->object->isSSLConnection(),
$this->equalTo(true)
);
}
}
58 changes: 20 additions & 38 deletions tests/suites/unit/joomla/application/JApplicationWebTest.php
Expand Up @@ -108,7 +108,6 @@ public function setUp()

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();

}

/**
Expand Down Expand Up @@ -1562,43 +1561,6 @@ public function testRedirectWithUrl($url, $base, $request, $expected)
);
}

/**
* Tests the JApplicationWeb::redirect method with webkit bug.
*
* @return void
*
* @since 11.3
*/
public function testRedirectWithWebkitBug()
{
$url = 'http://j.org/index.php';

// Inject the client information.
TestReflection::setValue(
$this->class,
'client',
(object) array(
'engine' => JApplicationWebClient::WEBKIT,
)
);

// Capture the output for this test.
ob_start();
$this->class->redirect($url);
$buffer = ob_get_contents();
ob_end_clean();

$this->assertThat(
trim($buffer),
$this->equalTo(
'<html><head>' .
'<meta http-equiv="refresh" content="0; url=' . $url . '" />' .
'<meta http-equiv="content-type" content="text/html; charset=utf-8" />' .
'</head><body></body></html>'
)
);
}

/**
* Tests the JApplicationWeb::registerEvent method.
*
Expand Down Expand Up @@ -1794,4 +1756,24 @@ public function testSetHeader()
'Tests that headers of the same name are replaced.'
);
}

/**
* @covers JApplicationWeb::isSSLConnection
*/
public function testIsSSLConnection()
{
unset($_SERVER['HTTPS']);

$this->assertThat(
$this->class->isSSLConnection(),
$this->equalTo(false)
);

$_SERVER['HTTPS'] = 'on';

$this->assertThat(
$this->class->isSSLConnection(),
$this->equalTo(true)
);
}
}
5 changes: 3 additions & 2 deletions tests/suites/unit/joomla/environment/JBrowserTest.php
Expand Up @@ -8,7 +8,6 @@
*/
class JBrowserTest extends PHPUnit_Framework_TestCase
{

/**
* @var JBrowser
*/
Expand Down Expand Up @@ -186,6 +185,9 @@ public function testIsMobile()
);
}

/**
* @covers JBrowser::isSSLConnection
*/
public function testIsSSLConnection()
{
unset($_SERVER['HTTPS']);
Expand All @@ -202,5 +204,4 @@ public function testIsSSLConnection()
$this->equalTo(true)
);
}

}

0 comments on commit e4bda8f

Please sign in to comment.