diff vendor/zendframework/zend-feed/src/PubSubHubbub/AbstractCallback.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents 5311817fb629
children
line wrap: on
line diff
--- a/vendor/zendframework/zend-feed/src/PubSubHubbub/AbstractCallback.php	Thu Feb 28 11:14:44 2019 +0000
+++ b/vendor/zendframework/zend-feed/src/PubSubHubbub/AbstractCallback.php	Thu Feb 28 13:11:55 2019 +0000
@@ -211,28 +211,31 @@
     protected function _detectCallbackUrl()
     {
         // @codingStandardsIgnoreEnd
-        $callbackUrl = '';
-        if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
-            $callbackUrl = $_SERVER['HTTP_X_ORIGINAL_URL'];
-        } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
-            $callbackUrl = $_SERVER['HTTP_X_REWRITE_URL'];
-        } elseif (isset($_SERVER['REQUEST_URI'])) {
-            $callbackUrl = $_SERVER['REQUEST_URI'];
-            $scheme = 'http';
-            if ($_SERVER['HTTPS'] == 'on') {
-                $scheme = 'https';
-            }
-            $schemeAndHttpHost = $scheme . '://' . $this->_getHttpHost();
-            if (strpos($callbackUrl, $schemeAndHttpHost) === 0) {
-                $callbackUrl = substr($callbackUrl, strlen($schemeAndHttpHost));
-            }
-        } elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
-            $callbackUrl = $_SERVER['ORIG_PATH_INFO'];
-            if (! empty($_SERVER['QUERY_STRING'])) {
-                $callbackUrl .= '?' . $_SERVER['QUERY_STRING'];
-            }
+        $callbackUrl = null;
+
+        // IIS7 with URL Rewrite: make sure we get the unencoded url
+        // (double slash problem).
+        $iisUrlRewritten = isset($_SERVER['IIS_WasUrlRewritten']) ? $_SERVER['IIS_WasUrlRewritten'] : null;
+        $unencodedUrl    = isset($_SERVER['UNENCODED_URL']) ? $_SERVER['UNENCODED_URL'] : null;
+        if ('1' == $iisUrlRewritten && ! empty($unencodedUrl)) {
+            return $unencodedUrl;
         }
-        return $callbackUrl;
+
+        // HTTP proxy requests setup request URI with scheme and host [and port]
+        // + the URL path, only use URL path.
+        if (isset($_SERVER['REQUEST_URI'])) {
+            $callbackUrl = $this->buildCallbackUrlFromRequestUri();
+        }
+
+        if (null !== $callbackUrl) {
+            return $callbackUrl;
+        }
+
+        if (isset($_SERVER['ORIG_PATH_INFO'])) {
+            return $this->buildCallbackUrlFromOrigPathInfo();
+        }
+
+        return '';
     }
 
     /**
@@ -247,19 +250,19 @@
         if (! empty($_SERVER['HTTP_HOST'])) {
             return $_SERVER['HTTP_HOST'];
         }
-        $scheme = 'http';
-        if ($_SERVER['HTTPS'] == 'on') {
-            $scheme = 'https';
-        }
-        $name = $_SERVER['SERVER_NAME'];
-        $port = $_SERVER['SERVER_PORT'];
-        if (($scheme == 'http' && $port == 80)
-            || ($scheme == 'https' && $port == 443)
+
+        $https  = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : null;
+        $scheme = $https === 'on' ? 'https' : 'http';
+        $name   = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
+        $port   = isset($_SERVER['SERVER_PORT']) ? (int) $_SERVER['SERVER_PORT'] : 80;
+
+        if (($scheme === 'http' && $port === 80)
+            || ($scheme === 'https' && $port === 443)
         ) {
             return $name;
         }
 
-        return $name . ':' . $port;
+        return sprintf('%s:%d', $name, $port);
     }
 
     /**
@@ -304,4 +307,38 @@
 
         return strlen(trim($body)) > 0 ? $body : false;
     }
+
+    /**
+     * Build the callback URL from the REQUEST_URI server parameter.
+     *
+     * @return string
+     */
+    private function buildCallbackUrlFromRequestUri()
+    {
+        $callbackUrl = $_SERVER['REQUEST_URI'];
+        $https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : null;
+        $scheme = $https === 'on' ? 'https' : 'http';
+        if ($https === 'on') {
+            $scheme = 'https';
+        }
+        $schemeAndHttpHost = $scheme . '://' . $this->_getHttpHost();
+        if (strpos($callbackUrl, $schemeAndHttpHost) === 0) {
+            $callbackUrl = substr($callbackUrl, strlen($schemeAndHttpHost));
+        }
+        return $callbackUrl;
+    }
+
+    /**
+     * Build the callback URL from the ORIG_PATH_INFO server parameter.
+     *
+     * @return string
+     */
+    private function buildCallbackUrlFromOrigPathInfo()
+    {
+        $callbackUrl = $_SERVER['ORIG_PATH_INFO'];
+        if (! empty($_SERVER['QUERY_STRING'])) {
+            $callbackUrl .= '?' . $_SERVER['QUERY_STRING'];
+        }
+        return $callbackUrl;
+    }
 }