use Symfony\Component\HttpFoundation\Response; $response = new Response(); $response->setVary('User-Agent');
use Symfony\Component\HttpFoundation\Response; $response = new Response(); $response->setVary(['Accept-Language', 'User-Agent']);
use Symfony\Component\HttpFoundation\Response; $response = new Response(); $response->headers->set('Vary', 'User-Agent'); $response->setVary('Accept-Language', false);In this example, we add `Accept-Language` to the existing Vary header value of `User-Agent`. The second parameter of `setVary` is set to `false`, which means that the existing Vary header value is not replaced but appended to. Overall, `setVary` is useful for ensuring that cached responses are only used for the same request headers. This helps prevent incorrect responses being returned from cache.