[HttpKernel] added support for weak etags and added a method to set all cookies
This commit is contained in:
parent
c840c294fa
commit
005051c389
@ -234,6 +234,16 @@ class Response
|
|||||||
return $this->cookies;
|
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.
|
* Sets response status code.
|
||||||
*
|
*
|
||||||
@ -526,7 +536,6 @@ class Response
|
|||||||
} else {
|
} else {
|
||||||
$this->headers->set('Last-Modified', $date->format(DATE_RFC2822));
|
$this->headers->set('Last-Modified', $date->format(DATE_RFC2822));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -539,12 +548,16 @@ class Response
|
|||||||
return $this->headers->get('ETag');
|
return $this->headers->get('ETag');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setEtag($etag = null)
|
public function setEtag($etag = null, $weak = false)
|
||||||
{
|
{
|
||||||
if (null === $etag) {
|
if (null === $etag) {
|
||||||
$this->headers->delete('Etag');
|
$this->headers->delete('Etag');
|
||||||
} else {
|
} else {
|
||||||
$this->headers->set('ETag', $etag);
|
if (0 !== strpos($etag, '"')) {
|
||||||
|
$etag = '"'.$etag.'"';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->headers->set('ETag', (true === $weak ? 'W/' : '').$etag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,9 +619,7 @@ class Response
|
|||||||
{
|
{
|
||||||
$lastModified = $request->headers->get('If-Modified-Since');
|
$lastModified = $request->headers->get('If-Modified-Since');
|
||||||
$notModified = false;
|
$notModified = false;
|
||||||
if ($etags = $request->headers->get('If-None-Match')) {
|
if ($etags = $request->getEtags()) {
|
||||||
$etags = preg_split('/\s*,\s*/', $etags);
|
|
||||||
|
|
||||||
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
|
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
|
||||||
} elseif ($lastModified) {
|
} elseif ($lastModified) {
|
||||||
$notModified = $lastModified == $this->headers->get('Last-Modified');
|
$notModified = $lastModified == $this->headers->get('Last-Modified');
|
||||||
|
Reference in New Issue
Block a user