Browse files

If we don't rewind the stream and use Rails and Rack, when Rails will…

… try to read the env[POST_BODY] it will crap out with: MultiJson::DecodeError (A JSON text must at least contain two octets!) in activesupport (3.2.2) lib/active_support/json/decoding.rb:12:in `decode'
  • Loading branch information...
1 parent 451f029 commit 95349cef9c8479a6f289f2dd6a107595743c7138 @costi costi committed May 1, 2012
Showing with 1 addition and 0 deletions.
  1. +1 −0 lib/rack/contrib/post_body_content_type_parser.rb
View
1 lib/rack/contrib/post_body_content_type_parser.rb
@@ -32,6 +32,7 @@ def call(env)
if Rack::Request.new(env).media_type == APPLICATION_JSON && (body = env[POST_BODY].read).length != 0
env.update(FORM_HASH => JSON.parse(body), FORM_INPUT => env[POST_BODY])
end
+ env[POST_BODY].rewind # somebody might try to read this stream
@app.call(env)
end

0 comments on commit 95349ce

Please sign in to comment.