Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/StreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function push($message): void
}
}

public function recv(float $timeout = -1.0)
public function recv(float $timeout = -1.0): array
{
if ($this->getStreamId() <= 0) {
$recv = false;
Expand All @@ -130,13 +130,27 @@ public function recv(float $timeout = -1.0)
if ($recv === false) {
throw $this->newException();
}

/** @var \Swoole\Http2\Response $recv */

// server ended the stream
if ($recv->pipeline === false) {
$this->streamId = 0;
return [null, 0, $recv];

// TODO: Consider whether there should throw an exception if the HTTP/2 pipeline ends with a non-zero or missing gRPC status.
// Personally, I would prefer not to expose the gRPC status externally
$grpcStatus = $recv->headers["grpc-status"] ?? 0;

if($grpcStatus != 0){
$grpcMessage = $response->headers['grpc-message'] ?? 'Unknown error';
}else{
$grpcMessage = null;
}

return [$grpcMessage, $grpcStatus, $recv];
}

return Parser::parseResponse($recv, $this->deserialize);
return [Parser::parseStreamMessage($recv->data, $this->deserialize), 0, $recv];
}

public function end(): void
Expand Down
Loading