diff options
author | xue <> | 2007-08-05 18:25:44 +0000 |
---|---|---|
committer | xue <> | 2007-08-05 18:25:44 +0000 |
commit | 19f7932e9d620ee324498860cead3c2ffb4db590 (patch) | |
tree | d75e0cbbf6ff3622e7a54e58c80294019bb9e4d8 /framework/Web | |
parent | 80b976ac1b562200aac71c0c8fb154d0c40524fe (diff) |
modified getBaseUrl to enable forcing HTTPS
Diffstat (limited to 'framework/Web')
-rw-r--r-- | framework/Web/THttpRequest.php | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 12eb1f0e..8fcb926e 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -110,7 +110,6 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar private $_services; private $_requestResolved=false; private $_enableCookieValidation=false; - private $_forceSecureConnection=null; /** * @var string request URL */ @@ -321,22 +320,6 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar return $_SERVER['REQUEST_METHOD']; } - /** - * @param boolean forces http or https on a uri - */ - public function setForceSecureConnection($value) - { - $this->_forceSecureConnection=TPropertyValue::ensureBoolean($value); - } - - /** - * @return boolean if https is forced on a uri - */ - public function getForceSecureConnection() - { - return $this->_forceSecureConnection; - } - /** * @return boolean if the request is sent via secure channel (https) */ @@ -370,11 +353,12 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar } /** + * @param boolean whether to use HTTPS instead of HTTP even if the current request is sent via HTTP * @return string schema and hostname of the requested URL */ - public function getBaseUrl() + public function getBaseUrl($forceSecureConnection=false) { - return ($this->getIsSecureConnection() || $this->getForceSecureConnection() ? "https://" : "http://") . $_SERVER ['HTTP_HOST']; + return ($this->getIsSecureConnection() || $forceSecureConnection ? "https://" : "http://") . $_SERVER ['HTTP_HOST']; } /** @@ -386,11 +370,12 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar } /** + * @param boolean whether to use HTTPS instead of HTTP even if the current request is sent via HTTP * @return string entry script URL (w/ host part) */ - public function getAbsoluteApplicationUrl() + public function getAbsoluteApplicationUrl($forceSecureConnection=false) { - return $this->getBaseUrl() . $this->getApplicationUrl(); + return $this->getBaseUrl($forceSecureConnection) . $this->getApplicationUrl(); } /** @@ -558,19 +543,21 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar * This method may append session information to the generated URL if needed. * You may provide your own URL manager module by setting {@link setUrlManager UrlManager} * to provide your own URL scheme. + * + * Note, the constructed URL does not contain the protocol and hostname part. + * You may obtain an absolute URL by prepending the constructed URL with {@link getBaseUrl BaseUrl}. * @param string service ID * @param string service parameter * @param array GET parameters, null if not needed * @param boolean whether to encode the ampersand in URL, defaults to true. * @param boolean whether to encode the GET parameters (their names and values), defaults to false. + * @param boolean whether to use HTTPS even if the current request is sent via HTTP * @return string URL * @see TUrlManager::constructUrl */ public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=true,$encodeGetItems=true) { $url=$this->_urlManager->constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); - if($this->getForceSecureConnection()!==null) - $url = $this->getBaseUrl().$url; if(defined('SID') && SID != '' && !$this->_cookieOnly) return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; else |