13
14
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
42
43
44
45
|
# File 'lib/billy/handlers/proxy_handler.rb', line 13
def handle_request(method, url, , body)
if handles_request?(method, url, , body)
req = EventMachine::HttpRequest.new(url, {
:inactivity_timeout => Billy.config.proxied_request_inactivity_timeout,
:connect_timeout => Billy.config.proxied_request_connect_timeout})
req = req.send(method.downcase, build_request_options(, body))
if req.error
return { :error => "Request to #{url} failed with error: #{req.error}" }
end
if req.response
response = process_response(req)
unless allowed_response_code?(response[:status])
if Billy.config.non_successful_error_level == :error
return { :error => "Request failed due to response status #{response[:status]} for '#{url}' which was not allowed." }
else
Billy.log(:warn, "puffing-billy: Received response status code #{response[:status]} for '#{url}'")
end
end
if cacheable?(url, response[:headers], response[:status])
Billy::Cache.instance.store(method.downcase, url, , body, response[:headers], response[:status], response[:content])
end
Billy.log(:info, "puffing-billy: PROXY #{method} succeeded for '#{url}'")
return response
end
end
nil
end
|