Skip to content

Commit ddf681c

Browse files
committed
dev
1 parent 64af567 commit ddf681c

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ezclient (1.7.1)
4+
ezclient (1.7.2)
55
http (>= 4)
66

77
GEM

lib/ezclient/client.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ def request(verb, url, **options)
2828

2929
keep_alive_timeout = options.delete(:keep_alive)
3030
api_auth = options.delete(:api_auth)
31+
ssl_context = options[:ssl_context]
3132

3233
if keep_alive_timeout
33-
client = persistent_client_registry.for(url, timeout: keep_alive_timeout)
34+
client = persistent_client_registry.for(
35+
url, ssl_context: ssl_context, timeout: keep_alive_timeout
36+
)
3437
else
3538
client = HTTP::Client.new
3639
end

lib/ezclient/persistent_client_registry.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,31 @@ def initialize
55
self.registry = {}
66
end
77

8-
def for(url, timeout:)
8+
def for(url, ssl_context:, timeout:)
99
cleanup_registry!
10-
uri = HTTP::URI.parse(url)
11-
registry[uri.origin] ||= EzClient::PersistentClient.new(uri.origin, timeout)
10+
11+
origin = get_origin(url)
12+
registry[origin] ||= {}
13+
14+
ssl_bucket = ssl_context ? get_cert_sha256(ssl_context.cert) : nil
15+
registry[origin][ssl_bucket] ||= EzClient::PersistentClient.new(origin, timeout)
1216
end
1317

1418
private
1519

1620
attr_accessor :registry
1721

22+
def get_cert_sha256(cert)
23+
Digest::SHA256.hexdigest(cert.to_der)
24+
end
25+
26+
def get_origin(url)
27+
HTTP::URI.parse(url).origin
28+
end
29+
1830
def cleanup_registry!
19-
registry.delete_if { |_origin, client| client.timed_out? }
31+
registry.each do |_origin, ssl_bucket_clients|
32+
ssl_bucket_clients.delete_if { |_ssl_bucket, client| client.timed_out? }
33+
end
2034
end
2135
end

lib/ezclient/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module EzClient
4-
VERSION = "1.7.1"
4+
VERSION = "1.7.2"
55
end

0 commit comments

Comments
 (0)