Skip to content

Commit 0dab557

Browse files
authored
Fix overwritten headers in Swoole response (#98)
1 parent 46d813f commit 0dab557

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"require": {
1313
"symfony/runtime": "^5.3 || ^6.0"
1414
},
15+
"conflict": {
16+
"ext-swoole": "<4.6.0"
17+
},
1518
"require-dev": {
1619
"illuminate/http": "^8.48",
1720
"swoole/ide-helper": "^4.6",

src/SymfonyHttpBridge.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public static function convertSwooleRequest(Request $request): SymfonyRequest
3838
public static function reflectSymfonyResponse(SymfonyResponse $sfResponse, Response $response): void
3939
{
4040
foreach ($sfResponse->headers->all() as $name => $values) {
41-
foreach ($values as $value) {
42-
$response->header($name, $value);
43-
}
41+
$response->header($name, $values);
4442
}
4543

4644
$response->status($sfResponse->getStatusCode());

tests/Unit/SymfonyHttpBridgeTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Swoole\Http\Request;
88
use Swoole\Http\Response;
99
use Symfony\Component\HttpFoundation\BinaryFileResponse;
10+
use Symfony\Component\HttpFoundation\Cookie;
1011
use Symfony\Component\HttpFoundation\File\UploadedFile;
1112
use Symfony\Component\HttpFoundation\HeaderBag;
1213
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
@@ -59,13 +60,22 @@ public function testThatSwooleRequestIsConverted(): void
5960

6061
public function testThatSymfonyResponseIsReflected(): void
6162
{
63+
$fooCookie = (string) new Cookie('foo', '123');
64+
$barCookie = (string) new Cookie('bar', '234');
65+
6266
$sfResponse = $this->createMock(SymfonyResponse::class);
63-
$sfResponse->headers = new HeaderBag(['X-Test' => 'Swoole-Runtime']);
67+
$sfResponse->headers = new HeaderBag([
68+
'X-Test' => 'Swoole-Runtime',
69+
'Set-Cookie' => [$fooCookie, $barCookie],
70+
]);
6471
$sfResponse->expects(self::once())->method('getStatusCode')->willReturn(201);
6572
$sfResponse->expects(self::once())->method('getContent')->willReturn('Test');
6673

6774
$response = $this->createMock(Response::class);
68-
$response->expects(self::once())->method('header')->with('x-test', 'Swoole-Runtime');
75+
$response->expects(self::exactly(2))->method('header')->withConsecutive(
76+
['x-test', ['Swoole-Runtime']],
77+
['set-cookie', [$fooCookie, $barCookie]]
78+
);
6979
$response->expects(self::once())->method('status')->with(201);
7080
$response->expects(self::once())->method('end')->with('Test');
7181

0 commit comments

Comments
 (0)