Page MenuHomePhabricator

MultiHttpClient should handle headers from __construct
Closed, ResolvedPublic

Description

Currently the MultiHttpClient can handle headers only when those are passed when calling $client->run() or $client->runMulti(). But there is no way to specify a set of default headers when initialising the client.

In cases when we want to pass some default headers (like telememetry), classes that use MultiHttpClient shouldn't worry about the telemetry as it's the HTTP Client responsibility to handle those. Those headers should be injected by HTTPFactory and MultiHttpClient should respect those.

Definition of done:

$client = MediaWikiServices::getInstance()
    ->getHttpRequestFactory()
    ->createMultiClient([
        'headers' => [
            'X-Request-Id' => 'hash'
        ]
   ]
);

$client->run([
    'method' => 'GET', 'url' => 'http://localhost:8080',
    'headers' => ['second' => 'another']
]);

Should send request to http://localhost:8080 with two headers:
X-Request-Id: hash and second: another.

Additionally - I noticed that when curl is not available, headers are not passed to Guzzle client.

Event Timeline

pmiazga renamed this task from MultiHttpClient should handle headers from __constructor to MultiHttpClient should handle headers from __construct.Aug 30 2023, 8:01 PM
pmiazga created this task.

Change 953728 had a related patch set uploaded (by Pmiazga; author: Pmiazga):

[mediawiki/core@master] http: Allow MultiHttpClient handle headers on construction phase

https://gerrit.wikimedia.org/r/953728

Change 954058 had a related patch set uploaded (by Pmiazga; author: Pmiazga):

[mediawiki/core@master] http: Inject telemtry headers when initializing MultiHttpClient

https://gerrit.wikimedia.org/r/954058

Change 953728 merged by jenkins-bot:

[mediawiki/core@master] http: Allow MultiHttpClient handle headers on construction phase

https://gerrit.wikimedia.org/r/953728