Skip to content
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

Leverage Request::getPayload() to populate the parsed body of PSR-7 requests #117

Merged
merged 1 commit into from
Jul 25, 2023
Merged

Leverage Request::getPayload() to populate the parsed body of PSR-7 requests #117

merged 1 commit into from
Jul 25, 2023

Conversation

AurelienPillevesse
Copy link

@AurelienPillevesse AurelienPillevesse commented Jul 21, 2023

I'm trying to send a POST request with the fields below and application/x-www-form-urlencoded header :

  • "city": "Paris"
  • "country": "France"

If I send it like that, the fields are understood and I have these fields when I display the Request :

  • [ "city": "Paris", "country": "France" ]

Now if I send the same POST request with application/json header (with the same fields but in JSON format) :

  • {"city":"Paris","country":"France"}

They are not understand and I have an empty Request :

  • []

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Thank you for your PR.

First of all "it works"/"it doesn't work" does not tell me what exactly "it" is that you want to be working. Please adjust the PR description, so the reader knows what exactly the feature is that you'd like to deliver here.

Secondly, we don't merge new features without any tests. That's a blocker.

@derrabus
Copy link
Member

Thank you. I think, we're almost there. 🙂

Leveraging the new getPayload() method to populate the parsed body of the PSR-7 request is a good idea.

The test that you've added covers the happy case well. But what happens if the JSON payload cannot be decoded? We should also have a test that covers this case.

@AurelienPillevesse
Copy link
Author

That's a good idea, I will add this test case tomorrow morning

@AurelienPillevesse
Copy link
Author

New tests have been added

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@derrabus derrabus changed the title Improve parsedBody in PsrHttpFactory for Symfony 6.3+ projects Leverage Request::getPayload() to populate the parsed body of PSR-7 requests Jul 25, 2023
@derrabus
Copy link
Member

Thank you @AurelienPillevesse.

@derrabus derrabus merged commit 6b2f5df into symfony:main Jul 25, 2023
6 checks passed
@andreladocruz
Copy link

getting error after updating to 2.3

Symfony\Component\HttpFoundation\Request::getPayload(): Return value must be of type Symfony\Component\HttpFoundation\InputBag, Symfony\Component\HttpFoundation\ParameterBag returned

@derrabus
Copy link
Member

Please report this to the symfony/symfony repo.

@WebHaZe
Copy link

WebHaZe commented Jul 26, 2023

getting error

TypeError: Symfony\Component\HttpFoundation\Request::getPayload(): Return value must be of type Symfony\Component\HttpFoundation\InputBag, Symfony\Component\HttpFoundation\ParameterBag returned in /var/www/vendor/symfony/http-foundation/Request.php:1517

It is unexpected critical issue in my project from yesterday. Please pay attention to it as fast as it possible.

@OskarStark
Copy link
Contributor

As @derrabus mentioned, please open a ticket on symfony/symfony.

In the meantime, you can also provide a PR to fix the issue yourself or pin the 2.2.0 version from before

@derrabus
Copy link
Member

Laravel people, this way: laravel/framework#47834

@derrabus
Copy link
Member

Please pay attention to it as fast as it possible.

Please don't boss people around.

I'm locking the PR now because I don't think we need more stack traces for the same Laravel issue.

@symfony symfony locked and limited conversation to collaborators Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants