8000 bug #49957 [ErrorHandler] Fix sending `Vary` header with `SerializerE… · enumag/symfony@0ccb053 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ccb053

Browse files
committed
bug symfony#49957 [ErrorHandler] Fix sending Vary header with SerializerErrorRenderer (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Fix sending `Vary` header with `SerializerErrorRenderer` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This mistake is way too easy to make :) Commits ------- 0c0d852 [ErrorHandler] Fix sending Vary header with SerializerErrorRenderer
2 parents e27a5a7 + 0c0d852 commit 0ccb053

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Symfony/Component/ErrorHandler/ErrorRenderer/SerializerErrorRenderer.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(SerializerInterface $serializer, $format, ErrorRende
5555
*/
5656
public function render(\Throwable $exception): FlattenException
5757
{
58-
$headers = [];
58+
$headers = ['Vary' => 'Accept'];
5959
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
6060
if ($debug) {
6161
$headers['X-Debug-Exception'] = rawurlencode($exception->getMessage());
@@ -66,19 +66,17 @@ public function render(\Throwable $exception): FlattenException
6666

6767
try {
6868
$format = \is_string($this->format) ? $this->format : ($this->format)($flattenException);
69-
$headers = [
70-
'Content-Type' => Request::getMimeTypes($format)[0] ?? $format,
71-
'Vary' => 'Accept',
72-
];
69+
$headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format;
7370

74-
return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
71+
$flattenException->setAsString($this->serializer->serialize($flattenException, $format, [
7572
'exception' => $exception,
7673
'debug' => $debug,
77-
]))
78-
->setHeaders($flattenException->getHeaders() + $headers);
74+
]));
7975
} catch (NotEncodableValueException $e) {
80-
return $this->fallbackErrorRenderer->render($exception);
76+
$flattenException = $this->fallbackErrorRenderer->render($exception);
8177
}
78+
79+
return $flattenException->setHeaders($flattenException->getHeaders() + $headers);
8280
}
8381

8482
public static function getPreferredFormat(RequestStack $requestStack): \Closure

0 commit comments

Comments
 (0)
0