mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
50a570f19e
closes #1832
40 lines
884 B
Ruby
40 lines
884 B
Ruby
module Fog
|
|
class Connection
|
|
|
|
def initialize(url, persistent=false, params={})
|
|
unless params.has_key?(:debug_response)
|
|
params[:debug_response] = true
|
|
end
|
|
params[:headers] ||= {}
|
|
params[:headers]['User-Agent'] ||= "fog/#{Fog::VERSION}"
|
|
@excon = Excon.new(url, params)
|
|
@persistent = persistent
|
|
end
|
|
|
|
def request(params, &block)
|
|
unless @persistent
|
|
reset
|
|
end
|
|
unless block_given?
|
|
if (parser = params.delete(:parser))
|
|
body = Nokogiri::XML::SAX::PushParser.new(parser)
|
|
params[:response_block] = lambda { |chunk, remaining, total| body << chunk }
|
|
end
|
|
end
|
|
|
|
response = @excon.request(params, &block)
|
|
|
|
if parser
|
|
body.finish
|
|
response.body = parser.response
|
|
end
|
|
|
|
response
|
|
end
|
|
|
|
def reset
|
|
@excon.reset
|
|
end
|
|
|
|
end
|
|
end
|