lib/rack/reverse_proxy.rb in rack-reverse-proxy-0.2.0 vs lib/rack/reverse_proxy.rb in rack-reverse-proxy-0.3.0

- old
+ new

@@ -19,25 +19,30 @@ if key =~ /HTTP_(.*)/ headers[$1] = value end } - res = Net::HTTP.start(uri.host, uri.port) { |http| + Net::HTTP.start(uri.host, uri.port) { |http| m = rackreq.request_method case m when "GET", "HEAD", "DELETE", "OPTIONS", "TRACE" - req = Net::HTTP.const_get(m.capitalize).new(uri.path, headers) + req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers) when "PUT", "POST" - req = Net::HTTP.const_get(m.capitalize).new(uri.path, headers) + req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers) + req.content_length = rackreq.body.length req.body_stream = rackreq.body else - raise "method not supported: #{method}" + raise "method not supported: #{m}" end - http.request(req) + body = '' + res = http.request(req) do |res| + res.read_body do |segment| + body << segment + end + end + [res.code, Rack::Utils::HeaderHash.new(res.to_hash), [body]] } - - [res.code, Rack::Utils::HeaderHash.new(res.to_hash), [res.body]] end private def get_matcher_and_url path