From 7a406355f8438ae77412847706f52f4ff8d8b073 Mon Sep 17 00:00:00 2001 From: Chrisludt Date: Tue, 8 Nov 2016 13:22:50 +0000 Subject: [PATCH] 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 --- includes/http/Http.php | 2 ++ includes/http/MWHttpRequest.php | 6 ++++++ 2 files changed, 8 insertions(+) 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" ]; -- 2.20.1