RFC2616 changes
This commit is contained in:
parent
b9a218a5c1
commit
f7d0f651a3
@ -98,7 +98,7 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
$this->fixContentType();
|
$this->fixContent();
|
||||||
|
|
||||||
return
|
return
|
||||||
sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
|
sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
|
||||||
@ -119,7 +119,7 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public function sendHeaders()
|
public function sendHeaders()
|
||||||
{
|
{
|
||||||
$this->fixContentType();
|
$this->fixContent();
|
||||||
|
|
||||||
// status
|
// status
|
||||||
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
|
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
|
||||||
@ -172,7 +172,6 @@ class Response
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->content = (string) $content;
|
$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));
|
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()
|
protected function fixContentType()
|
||||||
{
|
{
|
||||||
$charset = $this->charset ?: 'UTF-8';
|
$charset = $this->charset ?: 'UTF-8';
|
||||||
@ -759,4 +767,14 @@ class Response
|
|||||||
$this->headers->set('Content-Type', $this->headers->get('Content-Type').'; charset='.$charset);
|
$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');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class ResponseListener
|
|||||||
$response = $event->getResponse();
|
$response = $event->getResponse();
|
||||||
|
|
||||||
if ('HEAD' === $request->getMethod()) {
|
if ('HEAD' === $request->getMethod()) {
|
||||||
// cf. RFC2611 14.13
|
// cf. RFC2616 14.13
|
||||||
$length = $response->headers->get('Content-Length');
|
$length = $response->headers->get('Content-Length');
|
||||||
$response->setContent('');
|
$response->setContent('');
|
||||||
if ($length) {
|
if ($length) {
|
||||||
|
Reference in New Issue
Block a user