From 1e51639306bb8f8b4d4f636c1ef1db80a6ab9b7f Mon Sep 17 00:00:00 2001 From: Michael Bos Date: Wed, 1 Apr 2020 12:41:26 -0700 Subject: [PATCH] fix(http-server): return all headers with the same name joined by comma (#175) Co-authored-by: k911 --- .../HttpFoundation/ResponseProcessor.php | 4 +- .../HttpFoundation/ResponseProcessorTest.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 tests/Unit/Bridge/Symfony/HttpFoundation/ResponseProcessorTest.php diff --git a/src/Bridge/Symfony/HttpFoundation/ResponseProcessor.php b/src/Bridge/Symfony/HttpFoundation/ResponseProcessor.php index c6d3c903..cbc6f1c5 100644 --- a/src/Bridge/Symfony/HttpFoundation/ResponseProcessor.php +++ b/src/Bridge/Symfony/HttpFoundation/ResponseProcessor.php @@ -22,9 +22,7 @@ public function process(HttpFoundationResponse $httpFoundationResponse, SwooleRe } foreach ($httpFoundationResponse->headers->allPreserveCaseWithoutCookies() as $name => $values) { - foreach ($values as $value) { - $swooleResponse->header($name, (string) $value); - } + $swooleResponse->header($name, \implode(', ', $values)); } foreach ($httpFoundationResponse->headers->getCookies() as $cookie) { diff --git a/tests/Unit/Bridge/Symfony/HttpFoundation/ResponseProcessorTest.php b/tests/Unit/Bridge/Symfony/HttpFoundation/ResponseProcessorTest.php new file mode 100644 index 00000000..a8bdeac7 --- /dev/null +++ b/tests/Unit/Bridge/Symfony/HttpFoundation/ResponseProcessorTest.php @@ -0,0 +1,54 @@ +responseProcessor = new ResponseProcessor(); + $this->swooleResponse = $this->prophesize(SwooleResponse::class); + } + + public function testProcess(): void + { + $this->symfonyResponse = new HttpFoundationResponse( + 'success', + 200, + [ + 'Vary' => [ + 'Content-Type', + 'Authorization', + 'Origin', + ], + ] + ); + + $swooleResponse = $this->swooleResponse->reveal(); + $this->responseProcessor->process($this->symfonyResponse, $swooleResponse); + $this->swooleResponse->header('Vary', 'Content-Type, Authorization, Origin')->shouldBeCalled(); + } +}