Skip to content

Commit 502d9d2

Browse files
committed
Intercept Ruby HTTP even when net/http isn't imported
In some cases, just net/https may be imported. This works if net/http is imported too, but if not then interception relies entirely on the SSL_CERT_FILE variable. Unfortunately, in some environments (notably including Mac's default Ruby) that variable is ignored. With this change, we ensure that even if just net/https is required, our HTTP hook is always enabled.
1 parent 315be21 commit 502d9d2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

overrides/gems/net/https.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# require 'net/https' is not necessary in modern ruby, as net/http
2+
# can handle HTTPS all by itself. That said, it's still used in
3+
# places, and its use of require_relative to load 'http' means that
4+
# it avoids our net/http hook.
5+
6+
# When using standard OpenSSL that's not a big problem, because
7+
# we also set SSL_CERT_FILE, which ensures we trust the certificate.
8+
# In some environments though (default Mac Ruby installs) that
9+
# variable is ignored, and so the net/http hook is *necessary*.
10+
11+
# All this file does is import our hooked HTTP version, before
12+
# running the real module as normal, to guarantee the hook is
13+
# always in place in every case.
14+
15+
require_relative 'http'
16+
17+
# Remove this module from LOAD_PATH, so we can load the real one
18+
gem_override_path = File.expand_path('..', __dir__) # parent dir, we're a subfolder
19+
$LOAD_PATH.reject! { |path| File.expand_path(path) == gem_override_path }
20+
21+
# Load the real net/https module as normal
22+
require 'net/https'
23+
24+
# Put this override directory back on LOAD_PATH again
25+
$LOAD_PATH.unshift(gem_override_path)

0 commit comments

Comments
 (0)