Class: HTTPX::UNIX

Inherits:
TCP
  • Object
show all
Defined in:
lib/httpx/io/unix.rb,
sig/io/unix.rbs

Constant Summary

Constants included from Loggable

Loggable::COLORS, Loggable::USE_DEBUG_LOG

Instance Attribute Summary collapse

Attributes inherited from TCP

#addresses, #interests, #ip, #port, #state

Instance Method Summary collapse

Methods inherited from TCP

#add_addresses, #can_disconnect?, #close, #closed?, #connected?, #do_transition, #log_transition_state, #protocol, #read, #socket, #to_io, #transition, #try_connect, #write

Methods included from Loggable

#log, #log_exception, log_identifiers, #log_redact, #log_redact_body, #log_redact_headers

Constructor Details

#initialize(origin, path, options) ⇒ UNIX

Returns a new instance of UNIX.

Parameters:

  • origin (http_uri)
  • path (String, nil)
  • options (Options)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/httpx/io/unix.rb', line 11

def initialize(origin, path, options)
  @addresses = []
  @hostname = origin.host
  @state = :idle
  @options = options
  @fallback_protocol = @options.fallback_protocol
  if (io = @options.io)
    io =
      case io
      when Hash
        io[origin.authority]
      else
        io
      end
    raise Error, "Given IO objects do not match the request authority" unless io

    # @type var io: UNIXSocket

    _, @path = io.addr
    @io = io
    @keep_open = true
    @state = :connected
  elsif path
    @path = path
  else
    raise Error, "No path given where to store the socket"
  end
  @io ||= build_socket
end

Instance Attribute Details

#pathString (readonly) Also known as: host

Returns the value of attribute path.

Returns:

  • (String)


7
8
9
# File 'lib/httpx/io/unix.rb', line 7

def path
  @path
end

Instance Method Details

#addresses?Boolean

the path is always explicitly passed, so no point in resolving.

Returns:

  • (Boolean)


59
60
61
# File 'lib/httpx/io/unix.rb', line 59

def addresses?
  true
end

#build_socketSocket

Returns:

  • (Socket)


71
72
73
# File 'lib/httpx/io/unix.rb', line 71

def build_socket
  Socket.new(Socket::PF_UNIX, :STREAM, 0)
end

#connectvoid

This method returns an undefined value.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/httpx/io/unix.rb', line 41

def connect
  return unless closed?

  begin
    if @io.closed?
      transition(:idle)
      @io = build_socket
    end
    @io.connect_nonblock(Socket.sockaddr_un(@path))
  rescue Errno::EISCONN
  end
  transition(:connected)
rescue Errno::EINPROGRESS,
       Errno::EALREADY,
       IO::WaitReadable
end

#inspectObject

simplecov:disable



64
65
66
# File 'lib/httpx/io/unix.rb', line 64

def inspect
  "#<#{self.class}:#{object_id} @path=#{@path}) @state=#{@state})>"
end