Skip to content

Allow instantiating the Meilisearch client with custom HTTP headers #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public function __construct(
?ClientInterface $httpClient = null,
?RequestFactoryInterface $requestFactory = null,
array $clientAgents = [],
?StreamFactoryInterface $streamFactory = null
?StreamFactoryInterface $streamFactory = null,
$headers = []
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a type declaration (e.g. array) for the $headers parameter in the constructor to maintain consistency across the client API.

Copilot uses AI. Check for mistakes.

) {
$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);
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function __construct(
?ClientInterface $httpClient = null,
?RequestFactoryInterface $reqFactory = null,
array $clientAgents = [],
?StreamFactoryInterface $streamFactory = null
?StreamFactoryInterface $streamFactory = null,
$headers = []
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a type declaration (e.g. array) for the $headers parameter to improve API consistency and type safety.

Copilot uses AI. Check for mistakes.

) {
$this->baseUrl = $url;
$this->http = $httpClient ?? Psr18ClientDiscovery::find();
Expand All @@ -59,6 +60,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();
}

Expand Down
Loading