Skip to content

Commit 91dae03

Browse files
committed
Merge pull request #7 from brianewing/master
Send original Content-Type with proxied request, fixed exception when determining Content-Length
2 parents 77a21ee + 96c8f7b commit 91dae03

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/rack/reverse_proxy.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@ def call(env)
4444
when "PUT", "POST"
4545
req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers)
4646
req.basic_auth all_opts[:username], all_opts[:password] if all_opts[:username] and all_opts[:password]
47-
req.content_length = rackreq.body.size
47+
48+
if rackreq.body.respond_to?(:read) && rackreq.body.respond_to?(:rewind)
49+
body = rackreq.body.read
50+
req.content_length = body.size
51+
rackreq.body.rewind
52+
else
53+
req.content_length = rackreq.body.size
54+
end
55+
56+
req.content_type = rackreq.content_type unless rackreq.content_type.nil?
4857
req.body_stream = rackreq.body
4958
else
5059
raise "method not supported: #{m}"

0 commit comments

Comments
 (0)