-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,16 +166,42 @@ public function xmlHttpRequest(string $method, string $uri, array $parameters = | |
*/ | ||
public function jsonRequest(string $method, string $uri, array $parameters = [], array $server = [], bool $changeHistory = true): Crawler | ||
{ | ||
$content = json_encode($parameters); | ||
// Based on https://github.com/symfony/symfony/blob/v5.2.0/src/Symfony/Component/HttpFoundation/Request.php#L388-L404 | ||
// the logic in symfony/http-foundation we convert parameters to json content. | ||
switch (strtoupper($method)) { | ||
case 'POST': | ||
case 'PUT': | ||
case 'DELETE': | ||
case 'PATCH': | ||
$content = json_encode($parameters, \defined('JSON_THROW_ON_ERROR') ? \JSON_THROW_ON_ERROR : 0); | ||
$query = []; | ||
break; | ||
default: | ||
$content = null; | ||
$query = $parameters; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait, I'm not sure anymore that this makes sense: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
break; | ||
} | ||
|
||
$serverContentType = $this->getServerParameter('CONTENT_TYPE', null); | ||
$serverHttpAccept = $this->getServerParameter('HTTP_ACCEPT', null); | ||
|
||
$this->setServerParameter('CONTENT_TYPE', 'application/json'); | ||
$this->setServerParameter('HTTP_ACCEPT', 'application/json'); | ||
|
||
try { | ||
return $this->request($method, $uri, [], [], $server, $content, $changeHistory); | ||
return $this->request($method, $uri, $query, [], $server, $content, $changeHistory); | ||
} finally { | ||
unset($this->server['CONTENT_TYPE']); | ||
unset($this->server['HTTP_ACCEPT']); | ||
if (null === $serverContentType) { | ||
unset($this->server['CONTENT_TYPE']); | ||
} else { | ||
$this->setServerParameter('CONTENT_TYPE', $serverContentType); | ||
} | ||
|
||
if (null === $serverHttpAccept) { | ||
unset($this->server['HTTP_ACCEPT']); | ||
} else { | ||
$this->setServerParameter('HTTP_ACCEPT', $serverHttpAccept); | ||
} | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.