From: Tim Starling Date: Tue, 6 Oct 2015 01:07:29 +0000 (+1100) Subject: Add User-Agent support to MultiHttpClient requests X-Git-Tag: 1.31.0-rc.0~9537 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=6f51037d680ce;p=lhc%2Fweb%2Fwiklou.git Add User-Agent support to MultiHttpClient requests Because it is polite to send a User-Agent (and as part of T114558 investigation). Change-Id: I5096896d0891c0c9674ff8b4284aaa3ac7293c67 --- diff --git a/includes/libs/MultiHttpClient.php b/includes/libs/MultiHttpClient.php index 6af3ed5168..49966cf7bc 100644 --- a/includes/libs/MultiHttpClient.php +++ b/includes/libs/MultiHttpClient.php @@ -55,6 +55,8 @@ class MultiHttpClient { protected $maxConnsPerHost = 50; /** @var string|null proxy */ protected $proxy; + /** @var string */ + protected $userAgent = 'MW-MultiHttpClient'; /** * @param array $options @@ -63,6 +65,7 @@ class MultiHttpClient { * - proxy : HTTP proxy to use * - usePipelining : whether to use HTTP pipelining if possible (for all hosts) * - maxConnsPerHost : maximum number of concurrent connections (per host) + * - userAgent : The User-Agent header value to send * @throws Exception */ public function __construct( array $options ) { @@ -73,7 +76,7 @@ class MultiHttpClient { } } static $opts = array( - 'connTimeout', 'reqTimeout', 'usePipelining', 'maxConnsPerHost', 'proxy' + 'connTimeout', 'reqTimeout', 'usePipelining', 'maxConnsPerHost', 'proxy', 'userAgent' ); foreach ( $opts as $key ) { if ( isset( $options[$key] ) ) { @@ -343,6 +346,10 @@ class MultiHttpClient { $req['headers']['content-length'] = 0; } + if ( !isset( $req['headers']['user-agent'] ) ) { + $req['headers']['user-agent'] = $this->userAgent; + } + $headers = array(); foreach ( $req['headers'] as $name => $value ) { if ( strpos( $name, ': ' ) ) {