Skip to content

Commit

Permalink
[HttpKernel] added support for weak etags and added a method to set a…
Browse files Browse the repository at this point in the history
…ll cookies
  • Loading branch information
fabpot committed May 19, 2010
1 parent c840c29 commit 005051c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Symfony/Components/HttpKernel/Response.php
Expand Up @@ -234,6 +234,16 @@ public function getCookies()
return $this->cookies;
}

/**
* Sets cookies.
*
* @param array $cookies An array of cookies
*/
public function setCookies(array $cookies)
{
return $this->cookies = $cookies;
}

/**
* Sets response status code.
*
Expand Down Expand Up @@ -526,7 +536,6 @@ public function setLastModified(\DateTime $date = null)
} else {
$this->headers->set('Last-Modified', $date->format(DATE_RFC2822));
}

}

/**
Expand All @@ -539,12 +548,16 @@ public function getEtag()
return $this->headers->get('ETag');
}

public function setEtag($etag = null)
public function setEtag($etag = null, $weak = false)
{
if (null === $etag) {
$this->headers->delete('Etag');
} else {
$this->headers->set('ETag', $etag);
if (0 !== strpos($etag, '"')) {
$etag = '"'.$etag.'"';
}

$this->headers->set('ETag', (true === $weak ? 'W/' : '').$etag);
}
}

Expand Down Expand Up @@ -606,9 +619,7 @@ public function isNotModified(Request $request)
{
$lastModified = $request->headers->get('If-Modified-Since');
$notModified = false;
if ($etags = $request->headers->get('If-None-Match')) {
$etags = preg_split('/\s*,\s*/', $etags);

if ($etags = $request->getEtags()) {
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
} elseif ($lastModified) {
$notModified = $lastModified == $this->headers->get('Last-Modified');
Expand Down

0 comments on commit 005051c

Please sign in to comment.