Skip to content
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

Fix default headers merging #5

Merged
merged 2 commits into from
Nov 13, 2023
Merged
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
7 changes: 6 additions & 1 deletion src/DefaultRestClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

use function is_string;
use function strtolower;

/**
Expand Down Expand Up @@ -60,7 +61,11 @@ public function defaultHeaders(array $headers): static
foreach ($headers as $name => $values) {
$name = strtolower($name);
$this->defaultHeaders[$name] ??= [];
$this->defaultHeaders[$name] += $values;
if (is_string($values)) {
$this->defaultHeaders[$name][] = $values;
} else {
$this->defaultHeaders[$name][] += $values;
}
}

return $this;
Expand Down
8 changes: 6 additions & 2 deletions src/RestClientBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public function configure(DefinitionConfigurator $definition): void
->scalarNode('base_uri')
->info('The URI to resolve relative URLs, following rules in RFC 3985, section 2.')
->end()
->variableNode('default_headers')
->arrayNode('default_headers')
->info('Associative array of default headers: header => value(s).')
->defaultNull()
->defaultValue([])
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->normalizeKeys(false)
->variablePrototype()->end()
->end()
->end()
->end();
Expand Down
Loading