|
15 | 15 | use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
|
16 | 16 | use PHPUnit\Framework\TestCase;
|
17 | 17 | use Swoole\Coroutine;
|
| 18 | +use Swoole\Coroutine\Http\Server; |
18 | 19 | use Swoole\Tests\HookFlagsTrait;
|
19 | 20 |
|
20 | 21 | /**
|
@@ -262,4 +263,31 @@ public function testOptPrivate(): void
|
262 | 263 | curl_close($ch);
|
263 | 264 | });
|
264 | 265 | }
|
| 266 | + |
| 267 | + public function testRepeatHeader(): void |
| 268 | + { |
| 269 | + Coroutine\run(function () { |
| 270 | + $server = new Server('127.0.0.1', 0); |
| 271 | + Coroutine\go(function () use ($server) { |
| 272 | + $server->handle('/', function ($request, $response) { |
| 273 | + $response->header('X-Test-Header1', ['value1', 'value2']); |
| 274 | + $response->header('X-Test-Header2', 'value3'); |
| 275 | + $response->end(); |
| 276 | + }); |
| 277 | + $server->start(); |
| 278 | + }); |
| 279 | + $ch = curl_init('http://127.0.0.1:' . $server->port); |
| 280 | + curl_setopt($ch, CURLOPT_HEADER, true); |
| 281 | + curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Test-Header: value1', 'X-Test-Header: value2']); |
| 282 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 283 | + $response = curl_exec($ch); |
| 284 | + $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
| 285 | + $headers = substr($response, 0, $headerSize); |
| 286 | + $this->assertStringContainsStringIgnoringCase("x-test-header1: value1\r\n", $headers); |
| 287 | + $this->assertStringContainsStringIgnoringCase("x-test-header1: value2\r\n", $headers); |
| 288 | + $this->assertStringContainsStringIgnoringCase("x-test-header2: value3\r\n", $headers); |
| 289 | + $server->shutdown(); |
| 290 | + curl_close($ch); |
| 291 | + }); |
| 292 | + } |
265 | 293 | }
|
0 commit comments