Ver código fonte

ZF-9919: extended serverUrl helper to correctly identify scheme

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23370 44c647ce-9c0f-0410-b52a-842ac1e357ba
bittarman 15 anos atrás
pai
commit
ea1a12f329

+ 8 - 4
library/Zend/View/Helper/ServerUrl.php

@@ -52,10 +52,14 @@ class Zend_View_Helper_ServerUrl
      */
     public function __construct()
     {
-        if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)) {
-            $scheme = 'https';
-        } else {
-            $scheme = 'http';
+        switch (true) {
+            case (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)):
+            case (isset($_SERVER['HTTP_SCHEME']) && ($_SERVER['HTTP_SCHEME'] == 'https')):
+            case (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)):
+                $scheme = 'https';
+                break;
+            default:
+            $scheme = 'http';   
         }
         $this->setScheme($scheme);
 

+ 19 - 0
tests/Zend/View/Helper/ServerUrlTest.php

@@ -20,6 +20,7 @@
  * @version    $Id$
  */
 
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
 require_once 'PHPUnit/Framework/TestCase.php';
 require_once 'Zend/Controller/Front.php';
 require_once 'Zend/View/Helper/ServerUrl.php';
@@ -153,4 +154,22 @@ class Zend_View_Helper_ServerUrlTest extends PHPUnit_Framework_TestCase
         $url = new Zend_View_Helper_ServerUrl();
         $this->assertEquals('http://example.com', $url->serverUrl(new stdClass()));
     }
+
+    // ZF-9919
+    public function testServerUrlWithScheme()
+    {
+        $_SERVER['HTTP_SCHEME'] = 'https';
+        $_SERVER['HTTP_HOST'] = 'example.com';
+        $url = new Zend_View_Helper_ServerUrl();
+        $this->assertEquals('https://example.com', $url->serverUrl());
+    }
+
+    // ZF-9919
+    public function testServerUrlWithPort()
+    {
+        $_SERVER['SERVER_PORT'] = 443;
+        $_SERVER['HTTP_HOST'] = 'example.com';
+        $url = new Zend_View_Helper_ServerUrl();
+        $this->assertEquals('https://example.com', $url->serverUrl());
+    }
 }