def get(options, callback)
err = nil
begin
uri_hash = {}
uri_hash[:host] = options['hostname'] ? options['hostname'] : options['host']
path_components = options['path'] ? options['path'].split('?', 2) : ['']
if path_components.length > 1
uri_hash[:path] = path_components[0]
uri_hash[:query] = path_components[0]
else
uri_hash[:path] = path_components[0]
end
uri_hash[:port] = options['port'] ? options['port'] : Net::HTTP.http_default_port
uri_hash[:scheme] = uri_hash[:port] == Net::HTTP.https_default_port ? 'https' : 'http'
case uri_hash[:scheme]
when 'http'
uri = URI::HTTP.build(uri_hash)
when 'https'
uri = URI::HTTPS.build(uri_hash)
else
raise Exception, 'Less import only supports http and https'
end
http = Net::HTTP.new uri.host, uri.port
if uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = true
end
response = nil
http.start do |req|
response = req.get(uri.to_s)
end
sr = ServerResponse.new(response.read_body, response.code.to_i)
callback.call(sr)
rescue => e
err = e.message
ensure
ret = HttpNodeObj.new(err)
end
ret
end