Skip to content

Commit c2b7579

Browse files
committed
bug #30 Fix the request target in PSR7 Request (mtibben)
This PR was squashed before being merged into the 1.0-dev branch (closes #30). Discussion ---------- Fix the request target in PSR7 Request The request target is not being preserved correctly when using this library. This is because the query string is normalized, and we're not populating the PSR-7 request with the actual request target. This is important for things like http signatures which uses the request target as an input to sign a request. Commits ------- 94fcfa5 Fix the request target in PSR7 Request
2 parents 64640ee + 94fcfa5 commit c2b7579

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Factory/DiactorosFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function createRequest(Request $symfonyRequest)
5555
$request = new ServerRequest(
5656
$server,
5757
DiactorosRequestFactory::normalizeFiles($this->getFiles($symfonyRequest->files->all())),
58-
$symfonyRequest->getUri(),
58+
$symfonyRequest->getSchemeAndHttpHost().$symfonyRequest->getRequestUri(),
5959
$symfonyRequest->getMethod(),
6060
$body,
6161
$headers
@@ -65,6 +65,7 @@ public function createRequest(Request $symfonyRequest)
6565
->withCookieParams($symfonyRequest->cookies->all())
6666
->withQueryParams($symfonyRequest->query->all())
6767
->withParsedBody($symfonyRequest->request->all())
68+
->withRequestTarget($symfonyRequest->getRequestUri())
6869
;
6970

7071
foreach ($symfonyRequest->attributes->all() as $key => $value) {

Tests/Factory/DiactorosFactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function testCreateRequest()
6969
'REQUEST_METHOD' => 'POST',
7070
'HTTP_HOST' => 'dunglas.fr',
7171
'HTTP_X_SYMFONY' => '2.8',
72+
'REQUEST_URI' => '/testCreateRequest?foo=1&bar[baz]=42',
73+
'QUERY_STRING' => 'foo=1&bar[baz]=42',
7274
),
7375
'Content'
7476
);
@@ -81,6 +83,9 @@ public function testCreateRequest()
8183
$this->assertEquals('1', $queryParams['foo']);
8284
$this->assertEquals('42', $queryParams['bar']['baz']);
8385

86+
$requestTarget = $psrRequest->getRequestTarget();
87+
$this->assertEquals('/testCreateRequest?foo=1&bar[baz]=42', $requestTarget);
88+
8489
$parsedBody = $psrRequest->getParsedBody();
8590
$this->assertEquals('Kévin Dunglas', $parsedBody['twitter']['@dunglas']);
8691
$this->assertEquals('Les-Tilleuls.coop', $parsedBody['twitter']['@coopTilleuls']);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy