Sha256: 25d08dffe7fcf84ce88e55eaf3c6b342ce9516b68dd612882bd46e0af1cb25cf

Contents?: true

Size: 967 Bytes

Versions: 12

Compression:

Stored size: 967 Bytes

Contents

require 'net/http'

module Nodo
  class Client < Net::HTTP
    UNIX_REGEXP = /\Aunix:\/\//i

    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

    def connect
      if @socket_type == 'unix'
        connect_unix
      else
        super
      end
    end

    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
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nodo-1.7.1 lib/nodo/client.rb
nodo-1.7.0 lib/nodo/client.rb
nodo-1.6.5 lib/nodo/client.rb
nodo-1.6.4 lib/nodo/client.rb
nodo-1.6.3 lib/nodo/client.rb
nodo-1.6.2 lib/nodo/client.rb
nodo-1.6.1 lib/nodo/client.rb
nodo-1.6.0 lib/nodo/client.rb
nodo-1.5.6 lib/nodo/client.rb
nodo-1.5.5 lib/nodo/client.rb
nodo-1.5.4 lib/nodo/client.rb
nodo-1.5.3 lib/nodo/client.rb