Skip to content

Commit e7600d7

Browse files
committed
GET request params were not working
Body could be nil if stream was not finished transferring
1 parent e755a57 commit e7600d7

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/rack/reverse_proxy.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,27 @@ def call(env)
2121
end
2222
}
2323

24-
res = Net::HTTP.start(uri.host, uri.port) { |http|
24+
Net::HTTP.start(uri.host, uri.port) { |http|
2525
m = rackreq.request_method
2626
case m
2727
when "GET", "HEAD", "DELETE", "OPTIONS", "TRACE"
28-
req = Net::HTTP.const_get(m.capitalize).new(uri.path, headers)
28+
req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers)
2929
when "PUT", "POST"
30-
req = Net::HTTP.const_get(m.capitalize).new(uri.path, headers)
30+
req = Net::HTTP.const_get(m.capitalize).new(uri.request_uri, headers)
31+
req.content_length = rackreq.body.length
3132
req.body_stream = rackreq.body
3233
else
33-
raise "method not supported: #{method}"
34+
raise "method not supported: #{m}"
3435
end
3536

36-
http.request(req)
37+
body = ''
38+
res = http.request(req) do |res|
39+
res.read_body do |segment|
40+
body << segment
41+
end
42+
end
43+
[res.code, Rack::Utils::HeaderHash.new(res.to_hash), [body]]
3744
}
38-
39-
[res.code, Rack::Utils::HeaderHash.new(res.to_hash), [res.body]]
4045
end
4146

4247
private

0 commit comments

Comments
 (0)