-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: API\ResponseTrait can't return string as JSON #8490
Conversation
a286a7d
to
625628c
Compare
Unless we will be able to parse the same JSON on the input, I think I will not be in favor. IMO we should support the same JSON parsing options for both: Request and Response. |
We can parse the string JSON $routes->post('/', 'Home::index'); <?php
namespace App\Controllers;
class Home extends BaseController
{
public function index(): string
{
$json = $this->request->getJSON();
echo $json; exit;
}
} $ curl -H 'Content-Type: application/json' -d '"message"' localhost:8080/
message |
Sorry, looks like I was mistaken. I thought we had a problem with that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Many thanks, Kenjis.
e686a30
to
f8b41ab
Compare
Added changelog and upgrade guide. |
f8b41ab
to
cd2b2d2
Compare
PHP Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated
and will handle string data as JSON.
Test code should not set the conetnt type. ResponseTrait has the responsibility.
cd2b2d2
to
fac0fe2
Compare
Description
Fixes #8397
$this->respond()
returnstext/html
. But it should returnapplication/json
.$this->respond()
returnsapplication/json
.$this->respond()
returnsapplication/json
.Before:
After:
Checklist: