Hello there,
I have implemented a Mercure Hub with ReactPHP and I'm having troubles with request bodies.
I'm currently trying to achieve this:
POST /.well-known/mercure
Content-Type: application/x-www-form-urlencoded
topic=/foo&topic=/bar&data=foobar
Indeed, the Mercure protocol specification states that a topic /foo can have alternate IRIs such as /bar. The payload to be sent is not in the PHP format topic[]=foo&topic[]=bar but topic=/foo&topic=/bar which means that PHP, by default, considers that topic is a string with the only value /bar, which is not what I want.
And so is the React\Http\Middleware\RequestBodyParserMiddleware which internally relies on PHP's parse_str function.
So, I'd like to implement my own logic to parse the body payload by myself, but:
- It looks like ReactPHP removes any trace of the original body at some point (
$request->getBody() returns an empty string), when Content-Type is application/x-www-form-urlencoded (could not reproduce with a random content type)
- It looks like the only way to short-circuit the
RequestBodyParserMiddleware to introduce my own is to set an empty value for enable_post_data_reading in php.ini, but I cannot assume people who will use my project have this tricky tweak in their configuration.
Could we either:
- Not remove the original body of the request
- Introduce an interface for
RequestBodyParserMiddleware so that we could optionally replace it in Server's constructor
- Introduce an
array $config of options into Server's constructor so that we could pass an option to prevent parsing request bodies and let our own middlewares take care of this?
Thank you,
Ben
Hello there,
I have implemented a Mercure Hub with ReactPHP and I'm having troubles with request bodies.
I'm currently trying to achieve this:
Indeed, the Mercure protocol specification states that a topic
/foocan have alternate IRIs such as/bar. The payload to be sent is not in the PHP formattopic[]=foo&topic[]=barbuttopic=/foo&topic=/barwhich means that PHP, by default, considers thattopicis a string with the only value/bar, which is not what I want.And so is the
React\Http\Middleware\RequestBodyParserMiddlewarewhich internally relies on PHP'sparse_strfunction.So, I'd like to implement my own logic to parse the body payload by myself, but:
$request->getBody()returns an empty string), whenContent-Typeisapplication/x-www-form-urlencoded(could not reproduce with a random content type)RequestBodyParserMiddlewareto introduce my own is to set an empty value for enable_post_data_reading inphp.ini, but I cannot assume people who will use my project have this tricky tweak in their configuration.Could we either:
RequestBodyParserMiddlewareso that we could optionally replace it inServer's constructorarray $configof options intoServer's constructor so that we could pass an option to prevent parsing request bodies and let our own middlewares take care of this?Thank you,
Ben