Class: URLCanonicalize::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/url_canonicalize/transport.rb

Overview

Builds the connection for a destination, resolving the host through the fetch security policy. Injectable via the :transport option: anything responding to call(uri, options) and returning a Net::HTTP-compatible connection can replace it

Constant Summary collapse

DEFAULT_RESOLVER =

Resolved lazily so the destination policy can be stubbed in tests

lambda do |uri, options|
  URLCanonicalize::Destination.resolve(uri, options)
end

Instance Method Summary collapse

Constructor Details

#initialize(resolver: DEFAULT_RESOLVER) ⇒ Transport

Returns a new instance of Transport.



14
15
16
17
# File 'lib/url_canonicalize/transport.rb', line 14

def initialize(resolver: DEFAULT_RESOLVER)
  @resolver = resolver
  freeze
end

Instance Method Details

#call(uri, options) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/url_canonicalize/transport.rb', line 19

def call(uri, options)
  http = Net::HTTP.new(uri.host, uri.port, nil)

  http.ipaddr = @resolver.call(uri, options)
  configure_timeouts(http, options)
  configure_tls(http, uri)

  http
end