diff options
| author | mo khan <mo.khan@gmail.com> | 2020-06-12 18:12:49 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-06-12 18:12:49 -0600 |
| commit | 10a9b0b05a924d46accbdf99f2266ec8465d10b9 (patch) | |
| tree | 2e6b505aaf1a07959e3c3d960de15e0e955a68aa /lib/net | |
| parent | d98902ada1d46080f21d1e1f122dc29351db9368 (diff) | |
Update CHANGELOG and CI configuration
Diffstat (limited to 'lib/net')
| -rw-r--r-- | lib/net/hippie/client.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/net/hippie/client.rb b/lib/net/hippie/client.rb index 3cf32be..b7b42ec 100644 --- a/lib/net/hippie/client.rb +++ b/lib/net/hippie/client.rb @@ -19,15 +19,13 @@ module Net @logger = options.fetch(:logger, Net::Hippie.logger) @follow_redirects = options.fetch(:follow_redirects, 0) @http_connections = Hash.new do |hash, key| - uri = URI.parse(key.to_s) - build_http_for(uri).tap do |http| - hash[key] = http - end + scheme, host, port = key + build_http_for(scheme, host, port).tap { |http| hash[key] = http } end end def execute(uri, request, limit: follow_redirects, &block) - http = @http_connections[uri] + http = http_for(uri) response = http.request(request) if limit.positive? && response.is_a?(Net::HTTPRedirection) url = build_url_for(http, response['location']) @@ -92,11 +90,11 @@ module Net sleep delay end - def build_http_for(uri) - http = Net::HTTP.new(uri.host, uri.port) + def build_http_for(scheme, host, port) + http = Net::HTTP.new(host, port) http.read_timeout = @options.fetch(:read_timeout, 10) http.open_timeout = @options.fetch(:open_timeout, 10) - http.use_ssl = uri.scheme == 'https' + http.use_ssl = scheme == 'https' http.verify_mode = @options.fetch(:verify_mode, Net::Hippie.verify_mode) http.set_debug_output(logger) apply_client_tls_to(http) @@ -131,6 +129,11 @@ module Net "#{http.use_ssl? ? 'https' : 'http'}://#{http.address}#{path}" end + + def http_for(uri) + uri = URI.parse(uri.to_s) + @http_connections[[uri.scheme, uri.host, uri.port]] + end end end end |
