diff --git a/example/Gemfile.lock b/example/Gemfile.lock index 92c31a6..88dd0cf 100644 --- a/example/Gemfile.lock +++ b/example/Gemfile.lock @@ -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 diff --git a/lib/twirp/service.rb b/lib/twirp/service.rb index 7e7a41a..f5b58e6 100644 --- a/lib/twirp/service.rb +++ b/lib/twirp/service.rb @@ -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)