From 2b7c3c5b670683bf19c563b588e6532619e01bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Sun, 5 Apr 2026 21:57:31 +0200 Subject: [PATCH] fix: add QUERY_STRING to server bag in RequestConverter (#66) --- CHANGELOG.md | 4 ++++ src/DTO/RequestConverter.php | 1 + tests/RequestConverterTest.php | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f9b0e8..c14dd31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added `QUERY_STRING` to server bag in `RequestConverter` ([#66](https://github.com/crazy-goat/workerman-bundle/issues/66)) + - Enables `$request->server->get('QUERY_STRING')` to return query string + - Enables Symfony's `getQueryString()` to work correctly + - Added `SERVER_PORT` and `SERVER_NAME` to server bag in `RequestConverter` ([#65](https://github.com/crazy-goat/workerman-bundle/issues/65)) - Enables `$request->getPort()` for non-standard ports (8080, 8443, etc.) - Required for Symfony's `getPort()` to return correct value when Host header has no port diff --git a/src/DTO/RequestConverter.php b/src/DTO/RequestConverter.php index e5688f4..53c63b8 100644 --- a/src/DTO/RequestConverter.php +++ b/src/DTO/RequestConverter.php @@ -43,6 +43,7 @@ public static function toSymfonyRequest(\Workerman\Protocols\Http\Request $rawRe 'REMOTE_PORT' => $rawRequest->connection?->getRemotePort() ?? 0, 'SERVER_PORT' => $localPort ?? ($isHttps ? 443 : 80), 'SERVER_NAME' => $rawRequest->connection?->getLocalIp() ?? 'localhost', + 'QUERY_STRING' => $rawRequest->queryString(), ]; if ($isHttps) { diff --git a/tests/RequestConverterTest.php b/tests/RequestConverterTest.php index 445b20e..3bb3025 100644 --- a/tests/RequestConverterTest.php +++ b/tests/RequestConverterTest.php @@ -283,6 +283,27 @@ public function testServerPortDefaultsTo80WhenNoConnection(): void $this->assertSame(80, $symfonyRequest->server->get('SERVER_PORT')); } + public function testQueryStringFromRequest(): void + { + $buffer = "GET /test?foo=bar&baz=qux HTTP/1.1\r\nHost: localhost\r\n\r\n"; + $rawRequest = new Request($buffer); + + $symfonyRequest = RequestConverter::toSymfonyRequest($rawRequest); + + $this->assertSame('foo=bar&baz=qux', $symfonyRequest->server->get('QUERY_STRING')); + $this->assertSame('baz=qux&foo=bar', $symfonyRequest->getQueryString()); + } + + public function testQueryStringEmptyForNoQueryParams(): void + { + $buffer = "GET /test HTTP/1.1\r\nHost: localhost\r\n\r\n"; + $rawRequest = new Request($buffer); + + $symfonyRequest = RequestConverter::toSymfonyRequest($rawRequest); + + $this->assertSame('', $symfonyRequest->server->get('QUERY_STRING')); + } + public function testGetPortReturnsServerPortWhenNoHostHeader(): void { $buffer = "GET /test HTTP/1.1\r\n\r\n";