Skip to content

Commit e8babbd

Browse files
committed
bug symfony#44395 [HttpKernel] fix sending Vary: Accept-Language when appropriate (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] fix sending Vary: Accept-Language when appropriate | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - That's something I figured our while reviewing symfony#44386 and that we missed in symfony#43108: the `Vary` header should be sent when we use `Accept-Language`, not when we send `Content-Language`. /cc @chalasr Commits ------- afab34d [HttpKernel] fix sending Vary: Accept-Language when appropriate
2 parents 4693727 + afab34d commit e8babbd

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private function setLocale(Request $request)
7070
$request->setLocale($locale);
7171
} elseif ($this->useAcceptLanguageHeader && $this->enabledLocales && ($preferredLanguage = $request->getPreferredLanguage($this->enabledLocales))) {
7272
$request->setLocale($preferredLanguage);
73+
$request->attributes->set('_vary_by_language', true);
7374
}
7475
}
7576

src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function onKernelResponse(ResponseEvent $event)
5050

5151
if ($this->addContentLanguageHeader && !$response->isInformational() && !$response->isEmpty() && !$response->headers->has('Content-Language')) {
5252
$response->headers->set('Content-Language', $event->getRequest()->getLocale());
53+
}
54+
55+
if ($event->getRequest()->attributes->get('_vary_by_language')) {
5356
$response->setVary('Accept-Language', false);
5457
}
5558

0 commit comments

Comments
 (0)