poller 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,9 +11,14 @@
11
11
  # HttpProbe also expects a matcher to be passed in. The matcher must return
12
12
  # either 'true or 'false' when given the http_response for evaluation via
13
13
  # its 'matches?' method.
14
+ #
15
+ # SSL is supported but certificates are not verified.
16
+ #
17
+ # Basic Auth is also supported in case userinfo appears in URL.
14
18
 
15
19
  require 'uri'
16
20
  require 'net/http'
21
+ require 'net/https'
17
22
 
18
23
  module Poller
19
24
  module HTTP
@@ -21,14 +26,24 @@ module Poller
21
26
  class HttpProbe
22
27
 
23
28
  def initialize(url_s, matcher, proxy_hostname = nil, proxy_port = nil, proxy_user = nil, proxy_pwd = nil)
24
- @uri = URI(url_s)
29
+ @uri = URI.parse(url_s)
25
30
  @matcher = matcher
26
- @proxy = Net::HTTP::Proxy(proxy_hostname, proxy_port, proxy_user, proxy_pwd)
31
+ @proxy = Net::HTTP::Proxy(proxy_hostname, proxy_port, proxy_user, proxy_pwd).new(@uri.host, @uri.port)
27
32
  end
28
33
 
29
34
  def sample
30
35
  begin
31
- @http_response = @proxy.get_response(@uri)
36
+ # support SSL, not veryfing the SSL certificates (out of scope from my perspective)
37
+ if @uri.scheme == 'https'
38
+ @proxy.use_ssl = true
39
+ @proxy.verify_mode = OpenSSL::SSL::VERIFY_NONE
40
+ end
41
+ request = Net::HTTP::Get.new(@uri.request_uri)
42
+ # support basic auth if userinfo appears in url
43
+ if @uri.userinfo
44
+ request.basic_auth(@uri.user, @uri.password)
45
+ end
46
+ @http_response = @proxy.request(request)
32
47
  return if @http_response.class == Net::HTTPOK
33
48
  rescue Exception => e
34
49
  raise RuntimeError, "#sample caught an Exception of class #{e.class} with message: #{e.message}"
@@ -1,3 +1,3 @@
1
1
  module Poller
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-19 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec