Skip to content

Commit

Permalink
Merge pull request #65 from twitchtv/rewind_rack_input
Browse files Browse the repository at this point in the history
Rewind rack input when reading the request
  • Loading branch information
marioizquierdo authored Apr 23, 2021
2 parents e24df5d + b850667 commit 505b18c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
PATH
remote: ..
specs:
twirp (1.7.0)
twirp (1.7.2)
faraday (< 2)
google-protobuf (~> 3.0, >= 3.7.0)

GEM
remote: https://rubygems.org/
specs:
faraday (1.1.0)
faraday (1.3.0)
faraday-net_http (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords
google-protobuf (3.13.0)
faraday-net_http (1.0.1)
google-protobuf (3.15.8)
multipart-post (2.1.1)
rack (2.2.3)
ruby2_keywords (0.0.2)
ruby2_keywords (0.0.4)

PLATFORMS
ruby
Expand Down
4 changes: 3 additions & 1 deletion lib/twirp/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def route_request(rack_env, env)

input = nil
begin
input = Encoding.decode(rack_request.body.read, env[:input_class], content_type)
body_str = rack_request.body.read
rack_request.body.rewind # allow other middleware to read again (https://github.com/twitchtv/twirp-ruby/issues/50)
input = Encoding.decode(body_str, env[:input_class], content_type)
rescue => e
error_msg = "Invalid request body for rpc method #{method_name.inspect} with Content-Type=#{content_type}"
if e.is_a?(Google::Protobuf::ParseError)
Expand Down

0 comments on commit 505b18c

Please sign in to comment.