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

Event body parsing issue #1

Closed
radutopala opened this issue May 8, 2018 · 5 comments
Closed

Event body parsing issue #1

radutopala opened this issue May 8, 2018 · 5 comments
Labels

Comments

@radutopala
Copy link

@mnapoli I could only use the httpHandler after applying this patch, else $request was containing a gibberish array.. maybe it's only me..

Try with any of the json from https://apex.sh/docs/ping/webhooks/.

diff --git a/src/Bridge/Psr7/RequestFactory.php b/src/Bridge/Psr7/RequestFactory.php
index 8efae90..cd3e490 100644
--- a/src/Bridge/Psr7/RequestFactory.php
+++ b/src/Bridge/Psr7/RequestFactory.php
@@ -17,7 +17,7 @@ class RequestFactory
     {
         $method = $event['httpMethod'] ?? 'GET';
         $query = $event['queryStringParameters'] ?? [];
-        parse_str($event['body'] ?? '', $request);
+        $request = $event['body'] ?? '';
         $files = [];
         $uri = $event['requestContext']['path'] ?? '/';
         $headers = $event['headers'] ?? [];

Else, thanks for this wrapper 😄

@mnapoli
Copy link
Member

mnapoli commented May 8, 2018

Thanks! That's weird, I'm using POST requests on another project and that worked fine. I will do additional tests.

Oh wait maybe I should do parse_str only for specific POST requests. E.g. if it's a POST request but JSON is sent then you don't want the body to be parsed. I think that may be it.

@mnapoli mnapoli added the bug label May 8, 2018
@radutopala
Copy link
Author

Yeah, that should be it. I sent the json directly in the body.

@mnapoli
Copy link
Member

mnapoli commented May 9, 2018

The approach of Zend Expressive is interesting, they have a middleware that will apply the correct "strategy" of decoding the body based on the header: https://github.com/zendframework/zend-expressive-helpers/blob/master/src/BodyParams/BodyParamsMiddleware.php
The downside is that it's a middleware, and JSON decoding is not really something that PHP does natively. I don't want this package to do more than what PHP does natively, frameworks already deal with JSON.

Slim's approach in it's base PSR-7 implementation is simpler:

https://github.com/slimphp/Slim-Http/blob/305e7572084d6476939ffd9f71e388ab847ecbc3/src/Request.php#L122-L127

@radutopala
Copy link
Author

Slim's implementation looks natural and straightforward indeed.

@mnapoli
Copy link
Member

mnapoli commented May 9, 2018

#2 fixes this problem.

@mnapoli mnapoli closed this as completed in 8d024c6 May 9, 2018
mnapoli added a commit that referenced this issue May 9, 2018
Fix #1 Support for POST body
jvis pushed a commit to jvis/bref that referenced this issue Nov 1, 2018
jvis pushed a commit to jvis/bref that referenced this issue Nov 1, 2018
@mnapoli mnapoli mentioned this issue Dec 4, 2018
mnapoli pushed a commit that referenced this issue Apr 30, 2019
mnapoli pushed a commit that referenced this issue Jul 19, 2019
mnapoli pushed a commit that referenced this issue Jan 15, 2021
* Add plugin update to create zip file before deployment and zip download and extraction in layers

* Refactor JS code

* Fix hook event and add iamRoleStatements

* Add stripSlashes to s3 key

* Fix custom variable path

* Load jszip from node_modules folder

* Fix zip stuff

* Working vendor upload stuff

* Add hashed vendor zip file to excludes

* Extend check in bootstrap functions, update index.js and add before:remove:remove hook to clear vendor archives before deleting bucket

* Disable file rename and only store the renamed version in s3 bucket, fix initial bug with bucketname

* Add chalk coloring to console logs

* Implement fixes from review - move to headObject, remove additional then

* Define local constants instead of class variables and change log output

* Remove exclude for hashed vendor zip file

* Add vendor separation block to php docs

* Add s3 download and unzip to function layer, update serverless plugin and add iam access for lambda to s3 bucket vendor files

* Rewrite autoload_static.php from composer after extracting the vendor directory

* Extract php code from bootstrap files into BrefToolBox class and update layer Dockerfiles

* Update formating
brefphp-bot pushed a commit to brefphp-bot/bref that referenced this issue Nov 18, 2021
afu-dev pushed a commit to afu-dev/bref that referenced this issue Dec 23, 2021
Added documentation to fail a record from a batch
mnapoli pushed a commit that referenced this issue Sep 13, 2022
mnapoli pushed a commit that referenced this issue Nov 22, 2022
 #1325 Improve tests for basic auth and form data header
mnapoli added a commit that referenced this issue Feb 14, 2023
Fix #1 Support for POST body
mnapoli pushed a commit that referenced this issue Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants