Skip to content

Commit

Permalink
Compatible with swoole version 6.0 (#32)
Browse files Browse the repository at this point in the history

Co-authored-by: 10470 <[email protected]>
Co-authored-by: 李铭昕 <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent f041150 commit 90be814
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
os: [ ubuntu-latest ]
php-version: [ '8.1', '8.2', '8.3' ]
swoole-version: [ 'v5.0.3', 'v5.1.2', 'master' ]
swoole-version: [ 'v5.0.3', 'v5.1.6', 'v6.0.0', 'master' ]
exclude:
- php-version: '8.3'
swoole-version: 'v5.0.3'
Expand Down
6 changes: 5 additions & 1 deletion src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ private function decodeHeaders(array $headers): array
$result = [];
foreach ($headers as $name => $header) {
// The key of header is lower case.
$result[$name][] = $header;
if (is_array($header)) {
$result[$name] = $header;
} else {
$result[$name][] = $header;
}
}
if ($this->set_cookie_headers) {
$result['set-cookie'] = $this->set_cookie_headers;
Expand Down
2 changes: 1 addition & 1 deletion src/Signal.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class Signal implements SignalInterface
{
public static function wait(int $signo, float $timeout = -1): bool
{
return System::waitSignal($signo, $timeout);
return System::waitSignal($signo, $timeout) !== false;
}
}
15 changes: 12 additions & 3 deletions tests/Cases/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,27 @@ public function testGuzzleClientWithCookies()
public function testServerHeaders()
{
$this->runInCoroutine(function () {
// Co Client Won't support to get multi response headers.
$client = new Client('127.0.0.1', 9501);
$response = $client->request('GET', '/header');
$this->assertSame($response->body, implode(',', $response->headers['x-id']));
if (SWOOLE_VERSION_ID >= 60000) {
$this->assertSame($response->body, $response->headers['x-id'][1]);
} else {
// Co Client Won't support to get multi response headers.
$this->assertSame($response->body, implode(',', $response->headers['x-id']));
}

$client = new GuzzleHttp\Client([
'base_uri' => 'http://127.0.0.1:9501/',
'handler' => GuzzleHttp\HandlerStack::create(new CoroutineHandler()),
]);

$response = $client->get('/header');
$this->assertSame((string) $response->getBody(), $response->getHeaderLine('x-id'));
if (SWOOLE_VERSION_ID >= 60000) {
$this->assertSame((string) $response->getBody(), $response->getHeader('x-id')[1]);
} else {
// Co Client Won't support to get multi response headers.
$this->assertSame((string) $response->getBody(), $response->getHeaderLine('x-id'));
}

// When Swoole version > 4.5, The native curl support to get multi response headers.
if (SWOOLE_VERSION_ID >= 40600) {
Expand Down

0 comments on commit 90be814

Please sign in to comment.