Class: HttpConnectionOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/z-http/http_connection_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options) ⇒ HttpConnectionOptions

Returns a new instance of HttpConnectionOptions.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/z-http/http_connection_options.rb', line 5

def initialize(uri, options)
  @connect_timeout     = options[:connect_timeout] || 5        # default connection setup timeout
  @inactivity_timeout  = options[:inactivity_timeout] ||= 10   # default connection inactivity (post-setup) timeout

  @tls   = options[:tls] || options[:ssl] || {}
  @proxy = options[:proxy]

  if bind = options[:bind]
    @bind = bind[:host] || '0.0.0.0'

    # ZMachine will open a UNIX socket if bind :port
    # is explicitly set to nil
    @bind_port = bind[:port]
  end

  uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
  @https = uri.scheme == "https"
  uri.port ||= (@https ? 443 : 80)

  if proxy = options[:proxy]
    @host = proxy[:host]
    @port = proxy[:port]
  else
    @host = uri.host
    @port = uri.port
  end
end

Instance Attribute Details

#bindObject (readonly)

Returns the value of attribute bind.



2
3
4
# File 'lib/z-http/http_connection_options.rb', line 2

def bind
  @bind
end

#bind_portObject (readonly)

Returns the value of attribute bind_port.



2
3
4
# File 'lib/z-http/http_connection_options.rb', line 2

def bind_port
  @bind_port
end

#connect_timeoutObject (readonly)

Returns the value of attribute connect_timeout.



3
4
5
# File 'lib/z-http/http_connection_options.rb', line 3

def connect_timeout
  @connect_timeout
end

#hostObject (readonly)

Returns the value of attribute host.



2
3
4
# File 'lib/z-http/http_connection_options.rb', line 2

def host
  @host
end

#inactivity_timeoutObject (readonly)

Returns the value of attribute inactivity_timeout.



3
4
5
# File 'lib/z-http/http_connection_options.rb', line 3

def inactivity_timeout
  @inactivity_timeout
end

#portObject (readonly)

Returns the value of attribute port.



2
3
4
# File 'lib/z-http/http_connection_options.rb', line 2

def port
  @port
end

#proxyObject (readonly)

Returns the value of attribute proxy.



2
3
4
# File 'lib/z-http/http_connection_options.rb', line 2

def proxy
  @proxy
end

#tlsObject (readonly)

Returns the value of attribute tls.



2
3
4
# File 'lib/z-http/http_connection_options.rb', line 2

def tls
  @tls
end

Instance Method Details

#connect_proxy?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/z-http/http_connection_options.rb', line 37

def connect_proxy?
  @proxy && (@proxy[:type] == :http || @proxy[:type].nil?) && @https
end

#http_proxy?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/z-http/http_connection_options.rb', line 33

def http_proxy?
  @proxy && (@proxy[:type] == :http || @proxy[:type].nil?) && !@https
end

#socks_proxy?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/z-http/http_connection_options.rb', line 41

def socks_proxy?
  @proxy && (@proxy[:type] == :socks5)
end