Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e8babbd

Browse filesBrowse files
committed
bug #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 #44386 and that we missed in #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
Copy full SHA for e8babbd

File tree

2 files changed

+4
-0
lines changed
Filter options

2 files changed

+4
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php
+3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.