public function end(string $finalBody = null)
{
if ($this->state & self::ENDED) {
if (isset($finalBody)) {
throw new \LogicException("Cannot send body data: response output already ended");
}
return;
}
if (!($this->state & self::STARTED)) {
$this->setCookies();
// An @ (as opposed to a numeric length) indicates "no entity content"
$entityValue = isset($finalBody) ? \strlen($finalBody) : "@";
$headers = $this->headers;
$headers[":aerys-entity-length"] = $entityValue;
$this->codec->send($headers);
}
if (isset($finalBody)) {
$this->codec->send($finalBody);
}
$this->codec->send(null);
// Update the state *AFTER* the codec operation so that if it throws
// we can handle things appropriately in the server.
$this->state = self::ENDED | self::STARTED;
}