Module: Kurchatov::Mixin::Http
- Included in:
- Plugins::Riemann
- Defined in:
- lib/kurchatov/mixin/http.rb
Constant Summary collapse
- USER_AGENT =
"Kurchatov (Riemann client)".freeze
Instance Method Summary collapse
-
#http_get(url) ⇒ Object
return: body, http_code.
-
#rest_get(url) ⇒ Object
/path/to/file, ya.ru, a:[email protected].
Instance Method Details
#http_get(url) ⇒ Object
return: body, http_code
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kurchatov/mixin/http.rb', line 25 def http_get(url) uri = URI(url) req = Net::HTTP::Get.new(uri) req['User-Agent'] = USER_AGENT res = nil begin Net::HTTP.start(uri.hostname, uri.port) {|http| res = http.request(req)} rescue SocketError, Errno::ECONNREFUSED return nil, 0 end return res.body, res.code.to_i end |
#rest_get(url) ⇒ Object
/path/to/file, ya.ru, a:[email protected]
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kurchatov/mixin/http.rb', line 13 def rest_get(url) uri = URI(url) if uri.userinfo open("#{uri.scheme}://#{uri.hostname}:#{uri.port}#{uri.request_uri}", :http_basic_authentication => [uri.user, uri.password], 'User-Agent' => USER_AGENT).read else open(url, 'User-Agent' => USER_AGENT).read end end |