-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for raw body #11
Conversation
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.
I'm not sure that is a good idea
Hi, @roxblnfk. The inclusion of this configuration was discussed a lot on the RoadRunner side (roadrunner-server/roadrunner#1264) and I believe that implementing it in this package will bring the same possibility of use: For some cases it is necessary to get the body without any modification. Enabling raw_body setting will only send the body untouched when the content-type is application/x-www-form-urlencoded. I modified this PR so that it parses raw body only when the content-type is application/x-www-form-urlencoded. Without this PR, when the raw_body setting is enabled, the POST request fields cannot be accessed through the ServerRequestInterface::getParsedBody method, as is determined by PSR-7. One use case is when you need to get the body untouched to calculate the body's validation hash and still need to access the body's fields. |
I changed this PR e rebased the main branch to minimize side effects, please review it again. |
I think it should be responsibility of a PHP middleware. |
Yes, it may be a PHP middleware, but I think that is great if this package support it as it's a roadrunner's feature. |
Another detail is that in PHP Middleware the request class will already be a PSR-7, there will not be the \Spiral\RoadRunner\Http\Request::$parsed property, which is necessary to decide whether to convert the body. |
Hm. Probably it can be solved with passing |
@butschster I made the change in PR to only add a resquest attribute |
src/HttpWorker.php
Outdated
@@ -157,6 +157,8 @@ private function hydrateRequest(Request $request, array $context): void | |||
$request->cookies = (array)($context['cookies'] ?? []); | |||
$request->uploads = (array)($context['uploads'] ?? []); | |||
$request->parsed = (bool)$context['parsed']; | |||
|
|||
$request->attributes['_parsed_body'] = $request->parsed; |
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.
Attributed value looks better 👍
- The literal should be replaced with a public constant
- I think the key should contain some prefix like
rr_
orroadrunner
. @butschster WDYT?
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.
@roxblnfk, PR adjusted. 😉
Thank you @lainosantos for the contribution! |
Add support for raw_body config implemented at roadrunner-server/http#45
I did not identify any BC making parse of the raw body when it is not empty. Do you see any?