-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Default accessing structured request body to empty array #50664
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
I suggest changing that only for
|
i consider toArray / getPayload equivalent public API :) |
i mean, from the original issue, a throwing perhaps both POVs are equally valid, let me know if we prefer a getPayload specific solution 👍
it's kinda an implementation detail ;) |
@ro0NL if you don't know that the body is valid json, note that HttpKernel will automatically convert those exceptions to a 4xx response. |
it enables doing if the request content is actually corrupt, let it be bad JSON, then we should throw (which hasnt changed here) my point here is, toArray/getPayload should not be used for state checking IMHO, but a route/controller condition should |
@ro0NL if your endpoint expects JSON, sending an empty body is actually a corrupt request. |
im still not sure toArray conveys your endpoint expects JSON, at least not by its name 🙄 to me, and if i recall it correctly, it was designed to be an implementation detail btw, see also #50492 (comment) 😅 |
TLDR: toArray to me is a poor-man getPayload solution, and should have been deprecated |
@ro0NL we explicitly decided not to deprecate it immediately to make things easier for the ecosystem needing to support multiple version of Symfony. I would expect us to deprecate it in 7.1. |
to me proves JSON is an implementation detail in that sense the method is already bugged for not returning $_POST im gonna wait for toArray deprecation, so we can avoid this debate |
we should get rid of it |
Similar like in PHP
$_POST
is always type array, and in Symfony$request->request
is always array-ableThe state can be checked by other means (headers, method, etc.), if nessecary