Replies: 2 comments 1 reply
|
My guess is you are using the plugin :json_parser, error_handler: proc { raise $! }, parser: proc{|body| p body; JSON.parse(body)}If I had to guess, attempting to read the JSON input returns an empty string or nil, and then parsing that as JSON fails. If that isn't it, can you provide a minimal self-contained reproducible example showing this issue (or a failing spec)? |
|
Thank you very much @jeremyevans for your answer. With your suggestion I could have some debug info and see the body of the request. It turns out this is a Phusion Passenger Bug. When sending data to this server with no "chunked" transfer means that the requester does not tell the total content-length of its request. Instead it send body in packets, giving packet length at the beginning of each. The last packet you send must have no content and a length of zero. So the json body that Phusion Passenger passed to my app looked like : 45
{
"email": "email@email.com",
"event": "unsubscribe"
}
0
As you can see, the "content-length" infos "45" (at the beginning) and "0" (at the end) are able to get you into trouble when trying to parse json. So, I could not reproduce this bug in my dev environment where server is webrick. Think I should open a bug at Phusion Passenger, and meanwhile manually strip this infos for simple short requests with just one packet like this one. |
Uh oh!
There was an error while loading. Please reload this page.
Hi ! I'm trying to connect my roda app to an external webhook. The external website sends me a "POST" request, with json in the body (request header "CONTENT_TYPE"=>"application/json"). I do not control the request it is sending, and sometimes the "CONTENT_LENGTH" header is set, sometimes not. If it isn't, trying to access
request.paramswill make Roda halt the request and returns a 400 status without throwing any exception.I then configured my app to use invalid_request_body plugin
With no success. Still request halt, still no exceptions.
Getting the exception is not my main goal, through : I just want to be able to read the
request.paramseven if "CONTENT_LENGTH" is not set. (I was hopping an exception could have this params embedded somewhere in it.).Any help welcome ! I'm stuck.
All reactions