Module: Less::Loader::Http
- Defined in:
- lib/less/loader.rb
Overview
:nodoc:
Defined Under Namespace
Classes: HttpGetResult, ServerResponse
Class Method Summary collapse
Class Method Details
.get(options, callback) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/less/loader.rb', line 153 def self.get(, callback) err = nil begin #less always sends options as an object, so no need to check for string uri_hash = {} uri_hash[:host] = ['hostname'] ? ['hostname'] : ['host'] path_components = ['path'] ? ['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] = ['port'] ? ['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. ensure ret = HttpGetResult.new(err) end ret end |