Skip to content
This repository

Rewind the stream that holds the post body after reading from it #54

Merged
merged 2 commits into from over 1 year ago

2 participants

Constantin Gavrilescu Konstantin Haase
Constantin Gavrilescu
costi commented May 01, 2012

Rewind the stream that holds the post body. Rails also 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'

added some commits May 01, 2012
Constantin Gavrilescu 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'
95349ce
Constantin Gavrilescu Puts the rewind into the proper place 281be28
Konstantin Haase rkh merged commit 73975aa into from December 10, 2012
Konstantin Haase rkh closed this December 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

May 01, 2012
Constantin Gavrilescu 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'
95349ce
Constantin Gavrilescu Puts the rewind into the proper place 281be28
This page is out of date. Refresh to see the latest.
1  lib/rack/contrib/post_body_content_type_parser.rb
@@ -30,6 +30,7 @@ def initialize(app)
30 30
 
31 31
     def call(env)
32 32
       if Rack::Request.new(env).media_type == APPLICATION_JSON && (body = env[POST_BODY].read).length != 0
  33
+        env[POST_BODY].rewind # somebody might try to read this stream
33 34
         env.update(FORM_HASH => JSON.parse(body), FORM_INPUT => env[POST_BODY])
34 35
       end
35 36
       @app.call(env)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.