jenkins-bot has submitted this change and it was merged.

Change subject: Http::getProxy() method to get proxy configuration
......................................................................


Http::getProxy() method to get proxy configuration

MediaWiki currently uses two sources for proxy configuration:
        * the $wgHTTPProxy global configuration variable
        * the http_proxy environment variable

The HTTP proxy adress to use is a valuable information for
extensions handling directly HTTP requests instead of use
helper classes provided by the core to construct them.

This change offers an Http::getProxy() utility method to get
the configuration, regardless of the source.

Bug: T117954
Change-Id: I5df31845df71f05ac581f532cc9bd7a1fea25583
---
M includes/HttpFunctions.php
M tests/phpunit/includes/HttpTest.php
2 files changed, 33 insertions(+), 6 deletions(-)

Approvals:
  Chad: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php
index 60196ab..697391b 100644
--- a/includes/HttpFunctions.php
+++ b/includes/HttpFunctions.php
@@ -193,6 +193,26 @@
                        $uri
                );
        }
+
+       /**
+        * Gets the relevant proxy from $wgHTTPProxy/http_proxy (when set).
+        *
+        * @return mixed The proxy address or an empty string if not set.
+        */
+       public static function getProxy() {
+               global $wgHTTPProxy;
+
+               if ( $wgHTTPProxy ) {
+                       return $wgHTTPProxy;
+               }
+
+               $envHttpProxy = getenv( "http_proxy" );
+               if ( $envHttpProxy ) {
+                       return $envHttpProxy;
+               }
+
+               return "";
+       }
 }
 
 /**
@@ -369,8 +389,6 @@
         * @return void
         */
        public function proxySetup() {
-               global $wgHTTPProxy;
-
                // If there is an explicit proxy set and proxies are not 
disabled, then use it
                if ( $this->proxy && !$this->noProxy ) {
                        return;
@@ -380,10 +398,8 @@
                // local URL and proxies are not disabled
                if ( Http::isLocalURL( $this->url ) || $this->noProxy ) {
                        $this->proxy = '';
-               } elseif ( $wgHTTPProxy ) {
-                       $this->proxy = $wgHTTPProxy;
-               } elseif ( getenv( "http_proxy" ) ) {
-                       $this->proxy = getenv( "http_proxy" );
+               } else {
+                       $this->proxy = Http::getProxy();
                }
        }
 
diff --git a/tests/phpunit/includes/HttpTest.php 
b/tests/phpunit/includes/HttpTest.php
index ea4b646..246c609 100644
--- a/tests/phpunit/includes/HttpTest.php
+++ b/tests/phpunit/includes/HttpTest.php
@@ -63,6 +63,17 @@
        }
 
        /**
+        * @covers Http::getProxy
+        */
+       public function testGetProxy() {
+               $this->setMwGlobals( 'wgHTTPProxy', 'proxy.domain.tld' );
+               $this->assertEquals(
+                       'proxy.domain.tld',
+                       Http::getProxy()
+               );
+       }
+
+       /**
         * Feeds URI to test a long regular expression in Http::isValidURI
         */
        public static function provideURI() {

-- 
To view, visit https://gerrit.wikimedia.org/r/251483
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5df31845df71f05ac581f532cc9bd7a1fea25583
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Dereckson <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Dereckson <[email protected]>
Gerrit-Reviewer: Galorefitz <[email protected]>
Gerrit-Reviewer: IAlex <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to