From: Chad Horohoe Date: Tue, 19 Jul 2016 18:01:28 +0000 (-0700) Subject: HttpFunctions: Move isLocalUrl() into MWHttpRequest and make it private X-Git-Tag: 1.31.0-rc.0~6341^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=b47c1969434d935525900cdb476c3b157f41d536;p=lhc%2Fweb%2Fwiklou.git HttpFunctions: Move isLocalUrl() into MWHttpRequest and make it private Nothing else calls this, and it really shouldn't be used except for determining if a request should be proxied. While we're here, actually support HTTPS. Change-Id: I5edf47f75ebb7c1705d0c406ee7d19425f348eb4 --- diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 694bbb5fd7..54b057aec6 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -124,47 +124,6 @@ class Http { return Http::request( 'POST', $url, $options, $caller ); } - /** - * Check if the URL can be served by localhost - * - * @param string $url Full url to check - * @return bool - */ - public static function isLocalURL( $url ) { - global $wgCommandLineMode, $wgLocalVirtualHosts; - - if ( $wgCommandLineMode ) { - return false; - } - - // Extract host part - $matches = []; - if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) { - $host = $matches[1]; - // Split up dotwise - $domainParts = explode( '.', $host ); - // Check if this domain or any superdomain is listed as a local virtual host - $domainParts = array_reverse( $domainParts ); - - $domain = ''; - $countParts = count( $domainParts ); - for ( $i = 0; $i < $countParts; $i++ ) { - $domainPart = $domainParts[$i]; - if ( $i == 0 ) { - $domain = $domainPart; - } else { - $domain = $domainPart . '.' . $domain; - } - - if ( in_array( $domain, $wgLocalVirtualHosts ) ) { - return true; - } - } - } - - return false; - } - /** * A standard user-agent we can use for external requests. * @return string @@ -390,13 +349,54 @@ class MWHttpRequest { // Otherwise, fallback to $wgHTTPProxy if this is not a machine // local URL and proxies are not disabled - if ( Http::isLocalURL( $this->url ) || $this->noProxy ) { + if ( self::isLocalURL( $this->url ) || $this->noProxy ) { $this->proxy = ''; } else { $this->proxy = Http::getProxy(); } } + /** + * Check if the URL can be served by localhost + * + * @param string $url Full url to check + * @return bool + */ + private static function isLocalURL( $url ) { + global $wgCommandLineMode, $wgLocalVirtualHosts; + + if ( $wgCommandLineMode ) { + return false; + } + + // Extract host part + $matches = []; + if ( preg_match( '!^https?://([\w.-]+)[/:].*$!', $url, $matches ) ) { + $host = $matches[1]; + // Split up dotwise + $domainParts = explode( '.', $host ); + // Check if this domain or any superdomain is listed as a local virtual host + $domainParts = array_reverse( $domainParts ); + + $domain = ''; + $countParts = count( $domainParts ); + for ( $i = 0; $i < $countParts; $i++ ) { + $domainPart = $domainParts[$i]; + if ( $i == 0 ) { + $domain = $domainPart; + } else { + $domain = $domainPart . '.' . $domain; + } + + if ( in_array( $domain, $wgLocalVirtualHosts ) ) { + return true; + } + } + } + + return false; + } + /** * Set the user agent * @param string $UA