Skip to content

Commit 398ff17

Browse files
committed
HttpWorker::respond : add EOS parameter
1 parent 6eb1142 commit 398ff17

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/HttpWorker.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public function waitRequest(): ?Request
6565
/**
6666
* @throws \JsonException
6767
*/
68-
public function respond(int $status, string|Generator $body, array $headers = []): void
68+
public function respond(int $status, string|Generator $body, array $headers = [], bool $endOfStream = true): void
6969
{
7070
if ($body instanceof Generator) {
71-
$this->respondStream($status, $body, $headers);
71+
$this->respondStream($status, $body, $headers, $endOfStream);
7272
return;
7373
}
7474

@@ -77,10 +77,10 @@ public function respond(int $status, string|Generator $body, array $headers = []
7777
'headers' => $headers ?: (object)[],
7878
], \JSON_THROW_ON_ERROR);
7979

80-
$this->worker->respond(new Payload($body, $head));
80+
$this->worker->respond(new Payload($body, $head, $endOfStream));
8181
}
8282

83-
private function respondStream(int $status, Generator $body, array $headers = []): void
83+
private function respondStream(int $status, Generator $body, array $headers = [], bool $endOfStream = true): void
8484
{
8585
$head = \json_encode([
8686
'status' => $status,
@@ -94,7 +94,10 @@ private function respondStream(int $status, Generator $body, array $headers = []
9494
do {
9595
if (!$body->valid()) {
9696
$content = (string)$body->getReturn();
97-
$worker->respond(new Payload($content, $head, true));
97+
if ($endOfStream === false && $content === '') {
98+
return;
99+
}
100+
$worker->respond(new Payload($content, $head, $endOfStream));
98101
break;
99102
}
100103
$content = (string)$body->current();

0 commit comments

Comments
 (0)