Class: HQ::CheckSite::Script::CustomHTTP

Inherits:
Net::HTTP
  • Object
show all
Defined in:
lib/hq/check-site/script.rb

Overview

basically, we hijack the call to TCPSocket.open from Net::HTTP.connect, and modify the first parameter (the address) to the value provided as override_address

Defined Under Namespace

Modules: CustomSocket

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#override_address=(value) ⇒ Object (writeonly)

Sets the attribute override_address

Parameters:

  • value

    the value to set the attribute override_address to.



24
25
26
# File 'lib/hq/check-site/script.rb', line 24

def override_address=(value)
  @override_address = value
end

Instance Method Details

#connect(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/hq/check-site/script.rb', line 33

def connect *args
	begin
		Net::HTTP.const_set "TCPSocket", CustomSocket
		CustomSocket.override_address = @override_address
		return super *args
	ensure
		Net::HTTP.send :remove_const, "TCPSocket"
	end
end