From f88abd0a0cf3ca0684f1a72bb5e5513723646dbf Mon Sep 17 00:00:00 2001 From: Nathan Lafarge Date: Fri, 31 Jan 2025 20:23:48 +0100 Subject: [PATCH] add option to pass headers in the meilisearch client builder --- src/Client.php | 5 +++-- src/Http/Client.php | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 51271314..a80bd334 100644 --- a/src/Client.php +++ b/src/Client.php @@ -47,9 +47,10 @@ public function __construct( ?ClientInterface $httpClient = null, ?RequestFactoryInterface $requestFactory = null, array $clientAgents = [], - ?StreamFactoryInterface $streamFactory = null + ?StreamFactoryInterface $streamFactory = null, + $headers = [] ) { - $this->http = new MeilisearchClientAdapter($url, $apiKey, $httpClient, $requestFactory, $clientAgents, $streamFactory); + $this->http = new MeilisearchClientAdapter($url, $apiKey, $httpClient, $requestFactory, $clientAgents, $streamFactory, $headers); $this->index = new Indexes($this->http); $this->health = new Health($this->http); $this->version = new Version($this->http); diff --git a/src/Http/Client.php b/src/Http/Client.php index 2d5486e5..289103d4 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -41,7 +41,8 @@ public function __construct( ?ClientInterface $httpClient = null, ?RequestFactoryInterface $reqFactory = null, array $clientAgents = [], - ?StreamFactoryInterface $streamFactory = null + ?StreamFactoryInterface $streamFactory = null, + $headers = [] ) { $this->baseUrl = $url; $this->http = $httpClient ?? Psr18ClientDiscovery::find(); @@ -53,6 +54,7 @@ public function __construct( if (null !== $apiKey && '' !== $apiKey) { $this->headers['Authorization'] = \sprintf('Bearer %s', $apiKey); } + $this->headers = array_merge($this->headers, $headers); $this->json = new Json(); }