Closed mattrayner closed 6 years ago
It's cause Sinatra is poorly-behaved, I think. I'm not sure why it doesn't rewind the request for you.
Before releasing any more (after this fix), let's make sure we've got an example Rails app in addition to the Sinatra one. Ralyxa's primarily designed for Sinatra, but if Rails is a big use case let's support it properly.
The issue is essentially caused by ActionDispatch::Request.
Within Sinatra, you receive a Rack::Request
wrapped in a Sinatra::Request
object. Rack::Request
's body object is an IO-like object which once read must be rewound just like a StringIO.
Rails on the other hand does some Rails'y magic and ActionDispatch::Request
doesn't directly wrap Rack::Request
so calling request.body
generates a fresh IO-like object, meaning multiple calls to request.body
don't need to be rewound.
When building Alexa_validator
I encountered a number of edge cases that were caused by rewinding rails requests - calling rewind in instances where there is no request body raises an error for example
Makes sense, thanks!
Can you please provide an example to implement ralyxa on rails?
@Ujjwal1987 I'll dig out mine now and upload it
@Ujjwal1987 please remember this is a proof of concept, and I have only used it for testing: https://github.com/mattrayner/ralyxa-on-rails
We should try to call rewind only if rewind exists to prevent this error 👎
This is because the Rails request object handles reading differently