Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/Protocols/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -346,13 +347,13 @@
/**
* 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) {
Expand All @@ -375,7 +376,7 @@
}

if ($connection->headers) {
$response->withHeaders($connection->headers);

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 379 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().
$connection->headers = [];
}

Expand All @@ -386,15 +387,15 @@
clearstatcache();
$fileSize = (int)filesize($file);
$bodyLen = $length > 0 ? $length : $fileSize - $offset;
$response->withHeaders([

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - macos-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - windows-latest

Call to an undefined method Stringable::withHeaders().

Check failure on line 390 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withHeaders().
'Content-Length' => $bodyLen,
'Accept-Ranges' => 'bytes',
]);

if ($offset || $length) {
$offsetEnd = $offset + $bodyLen - 1;
$response->header('Content-Range', "bytes $offset-$offsetEnd/$fileSize");

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - macos-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - windows-latest

Call to an undefined method Stringable::header().

Check failure on line 397 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - windows-latest

Call to an undefined method Stringable::header().
$response->withStatus(206);

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - ubuntu-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-stable - macos-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - windows-latest

Call to an undefined method Stringable::withStatus().

Check failure on line 398 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 - prefer-lowest - windows-latest

Call to an undefined method Stringable::withStatus().
}
if ($bodyLen < 2 * 1024 * 1024) {
$connection->send($response . file_get_contents($file, false, null, $offset, $bodyLen), true);
Expand Down
Loading