15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/redrock/server.rb', line 15
def call env
request = Rack::Request.new env
http_method = request.request_method
request_body = request.body.read
= {}
env.each do |k, v|
[k.sub(/^HTTP_/, '')] = v if k =~ /^HTTP_|CONTENT_TYPE|CONTENT_LENGTH/
end
begin
::Net::HTTP.start(["HOST"]) do |http|
request_class = ::Net::HTTP.const_get(http_method.capitalize)
path = request.path_info
path << "?#{request.query_string}" unless request.query_string.empty?
request = request_class.new request.path_info,
request.body = request_body unless request_body.empty?
@response = http.request request
end
rescue WebMock::NetConnectNotAllowedError => e
return [500,
{"Content-Type" => "text/plain", "Content-Length" => e.message.length.to_s},
e.message]
end
= {}
@response.to_hash.each {|k,v| [k] = v.join "\n"}
.delete "status"
[@response.code, , @response.body]
end
|