Module: RequestVia::NetHTTP

Extended by:
NetHTTP
Included in:
NetHTTP
Defined in:
lib/request_via/net_http.rb

Constant Summary collapse

Build =
Freeze.(-> (host, port) {
  Net::HTTP.new(host, port)
})
IsNetHTTP =
Freeze.(-> object {
  object.instance_of?(Net::HTTP)
})

Instance Method Summary collapse

Instance Method Details

#call(uri, port = nil, open_timeout = nil, read_timeout = nil, net_http = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/request_via/net_http.rb', line 15

def call(uri, port = nil, open_timeout = nil, read_timeout = nil, net_http = nil)
  return net_http if IsNetHTTP.(net_http)

  net_http = build!(uri, port, net_http)

  net_http.open_timeout = Integer(open_timeout) unless open_timeout.nil?
  net_http.read_timeout = Integer(read_timeout) unless read_timeout.nil?

  return net_http unless uri.instance_of?(URI::HTTPS)

  set_https!(net_http)
end