Merge "http: Support HTTP Basic Authentication"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 1 Dec 2016 20:09:02 +0000 (20:09 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 1 Dec 2016 20:09:02 +0000 (20:09 +0000)
includes/http/Http.php
includes/http/MWHttpRequest.php

index a68a63b..8255bb3 100644 (file)
@@ -51,6 +51,8 @@ class Http {
         *    - userAgent           A user agent, if you want to override the default
         *                          MediaWiki/$wgVersion
         *    - logger              A \Psr\Logger\LoggerInterface instance for debug logging
+        *    - username            Username for HTTP Basic Authentication
+        *    - password            Password for HTTP Basic Authentication
         * @param string $caller The method making this request, for profiling
         * @return string|bool (bool)false on failure or a string on success
         */
index a42b6d0..fac052f 100644 (file)
@@ -119,6 +119,12 @@ class MWHttpRequest implements LoggerAwareInterface {
                if ( isset( $options['userAgent'] ) ) {
                        $this->setUserAgent( $options['userAgent'] );
                }
+               if ( isset( $options['username'] ) && isset( $options['password'] ) ) {
+                       $this->setHeader(
+                               'Authorization',
+                               'Basic ' . base64_encode( $options['username'] . ':' . $options['password'] )
+                       );
+               }
 
                $members = [ "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
                                "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" ];