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

Symfony (http foundation) request->getRequestUri() doesn't contain query string #268

Closed
Rastusik opened this issue Jul 7, 2020 · 4 comments · Fixed by #269 or #273
Closed

Symfony (http foundation) request->getRequestUri() doesn't contain query string #268

Rastusik opened this issue Jul 7, 2020 · 4 comments · Fixed by #269 or #273

Comments

@Rastusik
Copy link
Contributor

Rastusik commented Jul 7, 2020

Describe the bug
The creation of Http Request in the RequestFactory doesn't set the $_SERVER[REQUEST_URI] parameter to the $server variable, which results in wrong value returned by calling $request->getRequestUri().

Steps To Reproduce
When a Symfony app with swoole bundle with gets requested with an url like this: http://localhost:9501/twig?test=abc&wtf=123, calling $request->getRequestUri() somewhere in the code, will return '/twig'.

Expected behavior
The method call should return this value: /twig?test=abc&wtf=123

Reference in symfony's Http/Request code: https://github.com/symfony/http-foundation/blob/1b66b861f3ff55fb39c13822a0fc915018b5ac84/Request.php#L1005

Environment (please complete the following information):

  • OS: Linux
  • PHP Version: 7.3.15
  • Swoole Version: 4.4.8
  • Symfony Version: 5.1.1
  • Running in docker: Yes

Proposed fix
The bug happens because this line: https://github.com/symfony/http-foundation/blob/v5.1.1/Request.php#L413 isn't called by creating the Request instance in the RequestsFactory

One solution would be to add these two lines into the factory:

$queryString = $server['QUERY_STRING'] ?? '';
$server['REQUEST_URI'] = $server['REQUEST_URI'] . ($queryString !== '' ? '?' . $queryString : '');

Another solution would be to call Request::create(), instead of just calling the Request class constructor directly.

@Rastusik Rastusik added kind/bug/possible Something probably isn't working priority/important labels Jul 7, 2020
@k911
Copy link
Owner

k911 commented Jul 7, 2020

Yeah, definitely we should use a proper factory method to create a request object when they're available.

Do you want to provide a fix for that issue? @Rastusik

@k911 k911 added area/http-server area/security area/symfony-bundle kind/bug/confirmed Something isn't working and removed kind/bug/possible Something probably isn't working labels Jul 7, 2020
@Rastusik
Copy link
Contributor Author

Rastusik commented Jul 7, 2020

I looked into it, and I think the first solution is sufficient because there would need to be very similar two lines of code even with the proper factory method usage because the proper factory method needs the manually concatenated path anyway and it also needs a http method as a string parameter which I don't know how to obtain from swoole request, probably from $server[REQUEST_METHOD] ... Do you think this is worth investigating?

@k911
Copy link
Owner

k911 commented Jul 7, 2020

Yeah, I think it's worth investigating and probably we should also write a test that proves correct behavior.

@Rastusik
Copy link
Contributor Author

Rastusik commented Jul 7, 2020

Well, I did the investigation and the second solution would be to use this method: Request::create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null), but the uri parameter would need to be created in the request factory the same way as the simpler solution.

@k911 k911 changed the title Symfony (http foundation) request doesn't contain REQUEST_URI Symfony (http foundation) request->getUri() doesn't contain query string Jul 14, 2020
@k911 k911 changed the title Symfony (http foundation) request->getUri() doesn't contain query string Symfony (http foundation) request->getRequestUri() doesn't contain query string Jul 14, 2020
@k911 k911 closed this as completed in #273 Jul 14, 2020
k911 added a commit that referenced this issue Jul 15, 2020
* docs(readme): clarify state of HMR in bundle (#275) ([1e49f07](1e49f07)), closes [#275](#275) [#264](#264)
* fix(doctrine): autoconfigure EntityManagerHandler only when orm is available in symfony's container  ([87ede15](87ede15)), closes [#274](#274)
* fix(http): proper creation of $_SERVER['REQUEST_URI'] (#269) ([78bb42b](78bb42b)), closes [#269](#269)
* test(issue-268): add e2e test to ensure no regressions (#273) ([b9df907](b9df907)), closes [#273](#273) [#268](#268)
* build(deps-dev): bump friendsofphp/php-cs-fixer from 2.16.3 to 2.16.4 (#266) ([7acabd7](7acabd7)), closes [#266](#266)
* build(deps-dev): bump phpspec/prophecy-phpunit from 2.0.0 to 2.0.1 (#271) ([623923d](623923d)), closes [#271](#271)
* build(deps-dev): bump phpstan/phpstan from 0.12.30 to 0.12.31 (#265) ([4c750a7](4c750a7)), closes [#265](#265)
* build(deps-dev): bump phpstan/phpstan from 0.12.31 to 0.12.32 (#267) ([334b88f](334b88f)), closes [#267](#267)
* build(deps-dev): bump phpunit/phpunit from 9.2.5 to 9.2.6 (#272) ([2256702](2256702)), closes [#272](#272)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.