Skip to content

Commit 77febb6

Browse files
authored
Support verify_hostname (#25)
1 parent 2d35fce commit 77febb6

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

faraday-net_http_persistent.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
2525
spec.require_paths = ["lib"]
2626

2727
spec.add_dependency "faraday", "~> 2.5"
28-
spec.add_dependency "net-http-persistent", "~> 4.0"
28+
spec.add_dependency "net-http-persistent", ">= 4.0.4", "< 5"
2929
end

lib/faraday/adapter/net_http_persistent.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ def request_with_wrapped_block(http, env)
183183
ca_file: :ca_file,
184184
ssl_version: :version,
185185
min_version: :min_version,
186-
max_version: :max_version
186+
max_version: :max_version,
187+
verify_hostname: :verify_hostname
187188
}.freeze
188189

189190
def configure_ssl(http, ssl)
@@ -193,7 +194,7 @@ def configure_ssl(http, ssl)
193194
http_set(http, :cert_store, ssl_cert_store(ssl))
194195

195196
SSL_CONFIGURATIONS
196-
.select { |_, key| ssl[key] }
197+
.select { |_, key| !ssl[key].nil? }
197198
.each { |target, key| http_set(http, target, ssl[key]) }
198199
end
199200

spec/faraday/adapter/net_http_persistent_spec.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,18 @@
3737

3838
http = adapter.send(:connection, url: url, request: {})
3939

40-
# `pool` is only present in net_http_persistent >= 3.0
41-
expect(http.pool.size).to eq(5) if http.respond_to?(:pool)
40+
expect(http.pool.size).to eq(5)
41+
end
42+
43+
it "allows to set verify_hostname in SSL settings to false" do
44+
url = URI("https://example.com")
45+
46+
adapter = described_class.new(nil)
47+
48+
http = adapter.send(:connection, url: url, request: {})
49+
adapter.send(:configure_ssl, http, verify_hostname: false)
50+
51+
expect(http.verify_hostname).to eq(false)
4252
end
4353

4454
context "min_version" do
@@ -50,8 +60,7 @@
5060
http = adapter.send(:connection, url: url, request: {})
5161
adapter.send(:configure_ssl, http, min_version: :TLS1_2)
5262

53-
# `min_version` is only present in net_http_persistent >= 3.1 (UNRELEASED)
54-
expect(http.min_version).to eq(:TLS1_2) if http.respond_to?(:min_version)
63+
expect(http.min_version).to eq(:TLS1_2)
5564
end
5665
end
5766
end

0 commit comments

Comments
 (0)