diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d04c284..ae64812f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,7 +44,7 @@ jobs: command: composer update --${{ matrix.stability }} --prefer-lowest --prefer-dist --no-interaction --no-progress --ansi - name: Static analysis - #continue-on-error: true + continue-on-error: true run: composer analyze - name: Execute tests diff --git a/src/Connection/TcpConnection.php b/src/Connection/TcpConnection.php index 38310a54..69f16af7 100644 --- a/src/Connection/TcpConnection.php +++ b/src/Connection/TcpConnection.php @@ -457,6 +457,9 @@ public function send(mixed $sendBuffer, bool $raw = false): bool|null return false; } + // Fix null to empty string. + $sendBuffer ??= ''; + // Try to call protocol::encode($sendBuffer) before sending. if (false === $raw && $this->protocol !== null) { try { diff --git a/src/Protocols/Http.php b/src/Protocols/Http.php index 3d100e9e..8dcacc38 100644 --- a/src/Protocols/Http.php +++ b/src/Protocols/Http.php @@ -19,6 +19,7 @@ use Workerman\Connection\TcpConnection; use Workerman\Protocols\Http\Request; use Workerman\Protocols\Http\Response; +use Stringable; use function clearstatcache; use function ctype_xdigit; use function filesize; @@ -346,13 +347,13 @@ protected static function decodeChunked(string $buffer, int $headerEnd): array /** * Http encode. * - * @param string|Response $response + * @param string|Stringable $response * @param TcpConnection $connection * @return string */ - public static function encode(mixed $response, TcpConnection $connection): string + public static function encode(string|Stringable $response, TcpConnection $connection): string { - if (!is_object($response)) { + if (is_string($response)) { $extHeader = ''; $contentType = 'text/html;charset=utf-8'; foreach ($connection->headers as $name => $value) {