From b276829806704300f4270d64137287379418beb6 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Mon, 22 Jun 2015 20:59:05 +0200 Subject: [PATCH] Make proxy behaviour of detectServer() configurable Bug: T75510 Change-Id: Ia6540962f8d913d925547189e101124f76d969c7 --- includes/DefaultSettings.php | 8 ++++++++ includes/WebRequest.php | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0aba961fb9..a16bccb1ca 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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. * diff --git a/includes/WebRequest.php b/includes/WebRequest.php index b9c9b862ed..c99e4846db 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -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. -- 2.20.1