Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/DTO/RequestConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions tests/RequestConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading