Skip to content

Commit

Permalink
bug #44395 [HttpKernel] fix sending Vary: Accept-Language when approp…
Browse files Browse the repository at this point in the history
…riate (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
  • Loading branch information
fabpot committed Dec 1, 2021
2 parents 4693727 + afab34d commit e8babbd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private function setLocale(Request $request)
$request->setLocale($locale);
} elseif ($this->useAcceptLanguageHeader && $this->enabledLocales && ($preferredLanguage = $request->getPreferredLanguage($this->enabledLocales))) {
$request->setLocale($preferredLanguage);
$request->attributes->set('_vary_by_language', true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function onKernelResponse(ResponseEvent $event)

if ($this->addContentLanguageHeader && !$response->isInformational() && !$response->isEmpty() && !$response->headers->has('Content-Language')) {
$response->headers->set('Content-Language', $event->getRequest()->getLocale());
}

if ($event->getRequest()->attributes->get('_vary_by_language')) {
$response->setVary('Accept-Language', false);
}

Expand Down

0 comments on commit e8babbd

Please sign in to comment.