Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
fix(http-server): return all headers with the same name joined by com…
Browse files Browse the repository at this point in the history
…ma (#175)

Co-authored-by: k911 <konradobal@gmail.com>
  • Loading branch information
mab05k and k911 authored Apr 1, 2020
1 parent 0524047 commit 1e51639
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Bridge/Symfony/HttpFoundation/ResponseProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
54 changes: 54 additions & 0 deletions tests/Unit/Bridge/Symfony/HttpFoundation/ResponseProcessorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace K911\Swoole\Tests\Unit\Bridge\Symfony\HttpFoundation;

use K911\Swoole\Bridge\Symfony\HttpFoundation\ResponseProcessor;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Swoole\Http\Response as SwooleResponse;
use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse;

class ResponseProcessorTest extends TestCase
{
/**
* @var ResponseProcessor
*/
protected $responseProcessor;

/**
* @var null|HttpFoundationResponse
*/
protected $symfonyResponse;

/**
* @var null|ObjectProphecy|SwooleResponse
*/
protected $swooleResponse;

protected function setUp(): void
{
$this->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();
}
}

0 comments on commit 1e51639

Please sign in to comment.