module Less::Loader::Http

def self.get(options, callback)

def self.get(options, callback)
  err = nil
  begin
    #less always sends options as an object, so no need to check for string
    uri_hash = {}
    uri_hash[:host]     = options['hostname'] ? options['hostname'] : options['host']
    path_components = options['path'] ? options['path'].split('?', 2) : ['']  #have to do this because node expects path and query to be combined
    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'  #have to check this way because of node's http.get
    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
    callback.call ServerResponse.new(response.read_body, response.code.to_i)
  rescue => e
    err = e.message
  ensure
    ret = HttpGetResult.new(err)
  end
  ret
end