You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Falcon as http server for sinatra app that uses sinja for json:api.
I've encountered a problem that my request.body is always malformed json.
After digging in I've found that Falcon uses Protocol::HTTP1::Body::Fixed as body class which is not rewindable. method #content? reads first 2 bytes to check if request has body. after that #deserialize_request_body always retrieves part of content, because in this case env['rack.input'] is an instance of Falcon::Adapters::Input which silently ignores rewind, because it's underlying body Protocol::HTTP1::Body::Fixed does not respond to it. I want to leave this issue here - maybe someone will looking solution for same problem.
I think it worth for PR - we can use #empty? on body if it responds to #empty?.
my bugfix is following
moduleSinjaPatchdefcontent?returnrequest.body.size > 0ifrequest.body.respond_to?(:size)return !request.body.empty?ifrequest.body.respond_to?(:empty?)request.body.rewindrequest.body.read(1)endendmoduleFalconAdaptersInputPatchdefempty?@body.respond_to?(:empty?) ? @body.empty? : @body.sizeendendFalcon::Adapters::Input.includeFalconAdaptersInputPatch# must be added after `register Sinatra::JSONAPI` performed.MyApp.prependSinjaPatch
The text was updated successfully, but these errors were encountered:
I'm using Falcon as http server for sinatra app that uses sinja for json:api.
I've encountered a problem that my request.body is always malformed json.
After digging in I've found that Falcon uses
Protocol::HTTP1::Body::Fixed
as body class which is not rewindable. method#content?
reads first 2 bytes to check if request has body. after that#deserialize_request_body
always retrieves part of content, because in this caseenv['rack.input']
is an instance ofFalcon::Adapters::Input
which silently ignores rewind, because it's underlying bodyProtocol::HTTP1::Body::Fixed
does not respond to it. I want to leave this issue here - maybe someone will looking solution for same problem.I think it worth for PR - we can use
#empty?
on body if it responds to#empty?
.my bugfix is following
The text was updated successfully, but these errors were encountered: