1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/connection.rb
Paul Thornthwaite 70d2b9caa6 [core] Adds fog User-Agent header
As discussed in #1026 this adds a User Agent HTTP header to help identify
the version of fog is accessing APIs.

This revised version fixes issue #1310
2012-11-27 16:32:38 +00:00

36 lines
767 B
Ruby

module Fog
class Connection
def initialize(url, persistent=false, params={})
Excon.defaults[: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