|
@@ -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".
|
|
@@ -124,7 +124,7 @@ class Response
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- $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));
|
|
@@ -753,6 +753,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';
|
|
@@ -763,4 +772,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');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|