Skip to content

Fix jsonRequest in AbstractBrowser for GET methods #39281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Dec 2, 2020

Q A
Branch? 5.x
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

When implementing #38596 I was not aware of that $parameters are also used as queryParameters and are converted based on the Method here into query or request data. This I think should be handled the same way for the jsonRequest also instead of just unset the server variables we should to reset to the predefined server variables.

@alexander-schranz alexander-schranz force-pushed the bugfix/abstract-browser-json-request branch 3 times, most recently from cc1747f to 4d90a87 Compare December 2, 2020 09:59
@alexander-schranz alexander-schranz force-pushed the bugfix/abstract-browser-json-request branch from 4d90a87 to 589d06f Compare December 2, 2020 10:07
@alexander-schranz alexander-schranz changed the title Fix jsonRequest in AbstractBrowser for GET Methods [BrowserKit] Fix jsonRequest in AbstractBrowser for GET Methods Dec 2, 2020
@nicolas-grekas nicolas-grekas added this to the 5.x milestone Dec 23, 2020
@alexander-schranz
Copy link
Contributor Author

@nicolas-grekas anything missing here from my side?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(failures are false-positives)

break;
default:
$content = null;
$query = $parameters;
Copy link
Member

@nicolas-grekas nicolas-grekas Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, I'm not sure anymore that this makes sense: $parameters doesn't go through the processing of json_encode().
That means objects (that do or don't implement JsonSerializable) are going to be passed differently when using GET vs other verbs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah based on the method we set it a request body or not. This is based on the linked logic which symfony currently use here: https://github.com/symfony/symfony/blob/v5.2.0/src/Symfony/Component/HttpFoundation/Request.php#L388-L404
It does not make sense to convert query parameters to JSON as nobody will converted it back. Which is in the FosRestBundle and ApiPlatform converted into the $request->request attributes by the BodyListener.

@alexander-schranz
Copy link
Contributor Author

alexander-schranz commented Apr 26, 2021

@nicolas-grekas any update to this I think this still should match the same logic as the http foundation Request object, we are using this in @sulu and without this change it was really buggy and not usable in all cases with GET.

@OskarStark OskarStark changed the title [BrowserKit] Fix jsonRequest in AbstractBrowser for GET Methods [BrowserKit] Fix jsonRequest in AbstractBrowser for GET methods Aug 4, 2021
@fabpot fabpot modified the milestones: 5.4, 6.1 Nov 16, 2021
@alexander-schranz
Copy link
Contributor Author

@nicolas-grekas I still think this change is valid because of:

switch (strtoupper($method)) {
case 'POST':
case 'PUT':
case 'DELETE':
if (!isset($server['CONTENT_TYPE'])) {
$server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
}
// no break
case 'PATCH':
$request = $parameters;
$query = [];
break;
default:
$request = [];
$query = $parameters;
break;
}

And because of GET, HEAD, OPTION parameters are query strings and the content has no meaning: https://stackoverflow.com/questions/978061/http-get-with-request-body

But think this will not being merged as it is now open a long time?

@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@carsonbot carsonbot changed the title [BrowserKit] Fix jsonRequest in AbstractBrowser for GET methods Fix jsonRequest in AbstractBrowser for GET methods Feb 16, 2023
@nicolas-grekas
Copy link
Member

I think nobody understands the change :)
Also, GET with body can exist, eg with Elasticsearch
I'm closing because this didn't get traction and it's always possible to use another method for GET when you want that behavior I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants