Skip to content

Commit

Permalink
Merge pull request #23 from bookboon/hotfix/do-no-override-headers
Browse files Browse the repository at this point in the history
fix: api bundle will no longer overwrite headers that have already been set
  • Loading branch information
lkm authored Jul 20, 2022
2 parents 3b01aef + 582f073 commit 1cc2742
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Helper/GuzzleDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ class GuzzleDecorator
public static function decorate(HandlerStack $stack, ConfigurationHolder $config): HandlerStack
{
$stack->push(Middleware::mapRequest(function (RequestInterface $request) use ($config) {
$requestOut = $request
->withHeader(Headers::HEADER_LANGUAGE, self::createAcceptLanguageString($config->getLanguages()));
if (!$request->hasHeader(Headers::HEADER_LANGUAGE)) {
$request = $request
->withHeader(Headers::HEADER_LANGUAGE, self::createAcceptLanguageString($config->getLanguages()));
}

if (null !== $branding = $config->getBranding()) {
$requestOut = $requestOut->withHeader(Headers::HEADER_BRANDING, $branding);
if (!$request->hasHeader(Headers::HEADER_BRANDING) && null !== $branding = $config->getBranding()) {
$request = $request->withHeader(Headers::HEADER_BRANDING, $branding);
}
if (null !== $rotation = $config->getRotation()) {
$requestOut = $requestOut->withHeader(Headers::HEADER_ROTATION, $rotation);
if (!$request->hasHeader(Headers::HEADER_ROTATION) && null !== $rotation = $config->getRotation()) {
$request = $request->withHeader(Headers::HEADER_ROTATION, $rotation);
}
if (null !== $currency = $config->getCurrency()) {
$requestOut = $requestOut->withHeader(Headers::HEADER_CURRENCY, $currency);
if (!$request->hasHeader(Headers::HEADER_CURRENCY) && null !== $currency = $config->getCurrency()) {
$request = $request->withHeader(Headers::HEADER_CURRENCY, $currency);
}
if (null !== $premiumLevel = $config->getPremiumLevel()) {
$requestOut = $requestOut->withHeader(Headers::HEADER_PREMIUM, $premiumLevel);
if (!$request->hasHeader(Headers::HEADER_PREMIUM) && null !== $premiumLevel = $config->getPremiumLevel()) {
$request = $request->withHeader(Headers::HEADER_PREMIUM, $premiumLevel);
}

return $requestOut;
}));
return $request;
}), 'bookboon-api');

return $stack;
}
Expand Down

0 comments on commit 1cc2742

Please sign in to comment.