Make proxy behaviour of detectServer() configurable
authorGilles Dubuc <gdubuc@wikimedia.org>
Mon, 22 Jun 2015 18:59:05 +0000 (20:59 +0200)
committerGilles Dubuc <gdubuc@wikimedia.org>
Mon, 22 Jun 2015 19:19:22 +0000 (21:19 +0200)
Bug: T75510
Change-Id: Ia6540962f8d913d925547189e101124f76d969c7

includes/DefaultSettings.php
includes/WebRequest.php

index 0aba961..a16bccb 100644 (file)
@@ -82,6 +82,14 @@ $wgVersion = '1.26alpha';
  */
 $wgSitename = 'MediaWiki';
 
+/**
+ * When the wiki is running behind a proxy and this is set to true, assumes that the proxy exposes
+ * the wiki on the standard ports (443 for https and 80 for http).
+ * @var bool
+ * @since 1.26
+ */
+$wgAssumeProxiesUseDefaultProtocolPorts = true;
+
 /**
  * URL of the server.
  *
index b9c9b86..c99e484 100644 (file)
@@ -176,6 +176,8 @@ class WebRequest {
         * @return string
         */
        public static function detectServer() {
+               global $wgAssumeProxiesUseDefaultProtocolPorts;
+
                $proto = self::detectProtocol();
                $stdPort = $proto === 'https' ? 443 : 80;
 
@@ -186,13 +188,15 @@ class WebRequest {
                        if ( !isset( $_SERVER[$varName] ) ) {
                                continue;
                        }
+
                        $parts = IP::splitHostAndPort( $_SERVER[$varName] );
                        if ( !$parts ) {
                                // Invalid, do not use
                                continue;
                        }
+
                        $host = $parts[0];
-                       if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
+                       if ( $wgAssumeProxiesUseDefaultProtocolPorts && isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
                                // Bug 70021: Assume that upstream proxy is running on the default
                                // port based on the protocol. We have no reliable way to determine
                                // the actual port in use upstream.