Skip to content

Commit a54cce1

Browse files
committed
Override the http.rb gem to inject our proxy settings
1 parent f2294e5 commit a54cce1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

overrides/gems/http.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Remove this module from LOAD_PATH, so we can load the real one
2+
gem_override_path = File.expand_path(__dir__)
3+
$LOAD_PATH.reject! { |path| File.expand_path(path) == gem_override_path }
4+
5+
# Load http.rb, and inject our proxy settings as the default for all requests
6+
require 'http'
7+
module HTTP
8+
module RequestHttpToolkitExtensions
9+
def initialize(opts)
10+
if not opts[:proxy] or opts[:proxy].keys.size < 2
11+
proxy_from_env = URI(opts.fetch(:uri).to_s).find_proxy
12+
opts[:proxy] = {
13+
proxy_address: proxy_from_env.host,
14+
proxy_port: proxy_from_env.port
15+
}
16+
end
17+
super(opts)
18+
end
19+
end
20+
21+
class Request
22+
prepend RequestHttpToolkitExtensions
23+
end
24+
end
25+
26+
# Put this override directory back on LOAD_PATH
27+
$LOAD_PATH.unshift(gem_override_path)

0 commit comments

Comments
 (0)