def call(env)
super
client.transparent_gzip_decompression = true
if req = env[:request]
if proxy = req[:proxy]
configure_proxy proxy
end
if bind = req[:bind]
configure_socket bind
end
configure_timeouts req
end
if env[:url].scheme == 'https' && ssl = env[:ssl]
configure_ssl ssl
end
env[:body] = env[:body].read if env[:body].respond_to? :read
resp = client.request env[:method], env[:url],
:body => env[:body],
:header => env[:request_headers]
save_response env, resp.status, resp.body, resp.headers
@app.call env
rescue ::HTTPClient::TimeoutError, Errno::ETIMEDOUT
raise Faraday::Error::TimeoutError, $!
rescue ::HTTPClient::BadResponseError => err
if err.message.include?('status 407')
raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
else
raise Faraday::Error::ClientError, $!
end
rescue Errno::ECONNREFUSED, EOFError
raise Faraday::Error::ConnectionFailed, $!
rescue => err
if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
raise Faraday::SSLError, err
else
raise
end
end