Browse files

set an attribute to indicate if a ping request was proxied

  • Loading branch information...
1 parent 9bacbc2 commit f020c68b3400797643e9d775b509575fd3926382 Kevin Olbrich committed Jan 25, 2013
Showing with 7 additions and 1 deletion.
  1. +4 −1 lib/net/ping/http.rb
  2. +3 −0 test/test_net_ping_http.rb
View
5 lib/net/ping/http.rb
@@ -34,6 +34,9 @@ class Ping::HTTP < Ping
# Use GET request instead HEAD. The default is false.
attr_accessor :get_request
+ # was this ping proxied?
+ attr_accessor :proxied
+
# Creates and returns a new Ping::HTTP object. The default port is the
# port associated with the URI. The default timeout is 5 seconds.
#
@@ -128,7 +131,7 @@ def do_ping(uri)
headers["User-Agent"] = user_agent unless user_agent.nil?
Timeout.timeout(@timeout) do
http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new(uri.host, uri.port)
-
+ @proxied = http.proxy?
if @get_request == true
request = Net::HTTP::Get.new(uri_path)
else
View
3 test/test_net_ping_http.rb
@@ -184,20 +184,23 @@ def setup
@http = Net::Ping::HTTP.new(@uri)
@http.get_request = true
assert_true(@http.ping)
+ assert_true(@http.proxied)
end
test 'ping with https proxy' do
ENV['https_proxy'] = "http://proxymoxie:3128"
@http = Net::Ping::HTTP.new(@uri_https)
@http.get_request = true
assert_true(@http.ping)
+ assert_true(@http.proxied)
end
test 'ping with no_proxy' do
ENV['no_proxy'] = "google.com"
@http = Net::Ping::HTTP.new(@uri)
@http.get_request = true
assert_true(@http.ping)
+ assert_false(@http.proxied)
end
def teardown

0 comments on commit f020c68

Please sign in to comment.