Skip to content

Commit 6479d2e

Browse files
authored
Merge pull request #2 from stainless-sdks/dmeadows/fix-ssl-issue
Proposal: add workaround for SSL issues
2 parents eebaf5e + 2bdcafa commit 6479d2e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

examples/upload.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
# typed: strong
4+
5+
require_relative "../lib/imagekit"
6+
7+
client = Imagekit::Client.new(
8+
private_key: ENV.fetch("IMAGEKIT_PRIVATE_KEY", nil)
9+
)
10+
11+
begin
12+
response = client.files.upload(
13+
file: "https://www.example.com/public-url.jpg",
14+
file_name: "file-name.jpg"
15+
)
16+
17+
pp(response)
18+
end

lib/imagekit/internal/transport/pooled_net_requester.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ def connect(url)
3333
Net::HTTP.new(url.host, port).tap do
3434
_1.use_ssl = %w[https wss].include?(url.scheme)
3535
_1.max_retries = 0
36+
37+
# Temporary workaround for SSL verification issue on some
38+
# platforms. Similar to: https://github.com/stripe/stripe-ruby/pull/397
39+
# Without this fix you may see errors like:
40+
# .rbenv/versions/3.2.0/lib/ruby/3.2.0/net/protocol.rb:46:in `connect_nonblock':
41+
# SSL_connect returned=1 errno=0 peeraddr=52.23.130.57:443 state=error:
42+
# certificate verify failed (unable to get certificate CRL) (OpenSSL::SSL::SSLError)
43+
if _1.use_ssl?
44+
cert_store = OpenSSL::X509::Store.new
45+
cert_store.set_default_paths
46+
_1.cert_store = cert_store
47+
_1.verify_mode = OpenSSL::SSL::VERIFY_PEER
48+
end
3649
end
3750
end
3851

0 commit comments

Comments
 (0)