title: Symfony - Setting Cookie onKernelRequest
body: <p>i want to be able to set a Cookie onKernelRequest Method, but the cookie is not beeing set, 
  Everything else is working fine, what am missing here?
  What i want to achieve is that if the user is not logged in and doesnt have the cookie he should see the http basic auth headers.
  If the user is logged in or does have the cookie he has access to the preview domains without having to enter their user credentials in http basic auth. </p>
  
  <pre><code>const AUTH_USER = 'myuser';
  const AUTH_PW = 'mypass';
  
  public function sendAuthorizationHeader()
  {
      header('WWW-Authenticate: Basic realm="Preview Domain"');
      header('HTTP/1.0 401 Unauthorized');
      die();
  }
  
  public function onKernelRequest(GetResponseEvent $event)
  {
      if (!$event-&gt;isMasterRequest()) {
          return;
      }
  
      $request = $event-&gt;getRequest();
      $host = $request-&gt;getHost();
      $loginSuccessful = false;
  
      // check if we are on a preview domain
      if (preg_match('/^preview-\d+/', $host)) {
          $user = $request-&gt;getUser();
          $cookie = $request-&gt;cookies-&gt;get('preview_user');
          $phpAuthUser = $request-&gt;server-&gt;get('PHP_AUTH_USER');
          $phpAuthPw = $request-&gt;server-&gt;get('PHP_AUTH_PW');
  
          if (isset($phpAuthUser) &amp;&amp; isset($phpAuthPw)) {
              if ($phpAuthUser == self::AUTH_USER &amp;&amp; $phpAuthPw == self::AUTH_PW) {
                  $loginSuccessful = true;
              }
          } else if ($user === null &amp;&amp; $cookie === null) {
              $this-&gt;sendAuthorizationHeader();
          }
  
          if (!$loginSuccessful) {
              $this-&gt;sendAuthorizationHeader();
          } else {
              $cookie = new Cookie('preview_user', true, 86400, '/', null, false, false);
  
              $response = new Response();
              $response-&gt;headers-&gt;setCookie($cookie);
              $response-&gt;sendHeaders();
          }
      }
  }
  </code></pre>