RFC2616 changes

This commit is contained in:
lenar 2011-07-06 23:50:37 +03:00
parent b9a218a5c1
commit f7d0f651a3
2 changed files with 22 additions and 4 deletions

View File

@ -98,7 +98,7 @@ class Response
*/
public function __toString()
{
$this->fixContentType();
$this->fixContent();
return
sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
@ -119,7 +119,7 @@ class Response
*/
public function sendHeaders()
{
$this->fixContentType();
$this->fixContent();
// status
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
@ -172,7 +172,6 @@ class Response
}
$this->content = (string) $content;
$this->headers->set('Content-Length', strlen($this->content));
}
/**
@ -749,6 +748,15 @@ class Response
return in_array($this->statusCode, array(201, 204, 304));
}
protected function fixContent()
{
if ($this->isInformational() || in_array($this->statusCode, array(204, 304))) {
$this->setContent('');
}
$this->fixContentType();
$this->fixContentLength();
}
protected function fixContentType()
{
$charset = $this->charset ?: 'UTF-8';
@ -759,4 +767,14 @@ class Response
$this->headers->set('Content-Type', $this->headers->get('Content-Type').'; charset='.$charset);
}
}
protected function fixContentLength()
{
if (!$this->headers->has('Content-Length')) {
$this->headers->set('Content-Length', strlen($this->content));
}
if ($this->headers->has('Transfer-Encoding')) {
$this->headers->remove('Content-Length');
}
}
}

View File

@ -40,7 +40,7 @@ class ResponseListener
$response = $event->getResponse();
if ('HEAD' === $request->getMethod()) {
// cf. RFC2611 14.13
// cf. RFC2616 14.13
$length = $response->headers->get('Content-Length');
$response->setContent('');
if ($length) {