Class: Nodo::Client
- Inherits:
-
Net::HTTP
- Object
- Net::HTTP
- Nodo::Client
- Defined in:
- lib/nodo/client.rb
Constant Summary collapse
- UNIX_REGEXP =
/\Aunix:\/\//i
Instance Method Summary collapse
- #connect ⇒ Object
- #connect_unix ⇒ Object
-
#initialize(address, port = nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(address, port = nil) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/nodo/client.rb', line 7 def initialize(address, port = nil) super(address, port) case address when UNIX_REGEXP @socket_type = 'unix' @socket_path = address.sub(UNIX_REGEXP, '') # Host header is required for HTTP/1.1 @address = 'localhost' @port = 80 else @socket_type = 'inet' end end |
Instance Method Details
#connect ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/nodo/client.rb', line 21 def connect if @socket_type == 'unix' connect_unix else super end end |
#connect_unix ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/nodo/client.rb', line 29 def connect_unix s = Timeout.timeout(@open_timeout) { UNIXSocket.open(@socket_path) } @socket = Net::BufferedIO.new(s, read_timeout: @read_timeout, write_timeout: @write_timeout, continue_timeout: @continue_timeout, debug_output: @debug_output) on_connect end |