From: Chrisludt Date: Tue, 8 Nov 2016 13:22:50 +0000 (+0000) Subject: http: Support HTTP Basic Authentication X-Git-Tag: 1.31.0-rc.0~4700^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=7a406355f8438ae77412847706f52f4ff8d8b073 http: Support HTTP Basic Authentication Adds two new options (username and password) to the MWHttpRequest (and HTTP helper class) to enable support for HTTP Basic Authentication on outgoing HTTP connections. Change-Id: If83f025bbe63769ba7bb4a824c5f12d5f1ec640a --- diff --git a/includes/http/Http.php b/includes/http/Http.php index 43ae2d0e8f..133d420213 100644 --- a/includes/http/Http.php +++ b/includes/http/Http.php @@ -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 */ diff --git a/includes/http/MWHttpRequest.php b/includes/http/MWHttpRequest.php index 08883ae44f..931860535c 100644 --- a/includes/http/MWHttpRequest.php +++ b/includes/http/MWHttpRequest.php @@ -116,6 +116,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" ];