public function stream(string $partialBody) : \Amp\Promise
{
if ($this->state & self::ENDED) {
throw new \LogicException("Cannot stream: response already sent");
}
if (!($this->state & self::STARTED)) {
$this->setCookies();
// A * (as opposed to a numeric length) indicates "streaming entity content"
$headers = $this->headers;
$headers[":aerys-entity-length"] = "*";
$this->codec->send($headers);
}
$this->codec->send($partialBody);
// Don't update the state until *AFTER* the codec operation so that if
// it throws we can handle InternalFilterException appropriately in the server.
$this->state = self::STREAMING | self::STARTED;
return $this->client->bufferPromisor ? $this->client->bufferPromisor->promise() : new \Amp\Success();
}