Skip to content

Commit

Permalink
Stop using an obsolete method of Net::HTTP (#8408)
Browse files Browse the repository at this point in the history
https://docs.ruby-lang.org/en/2.7.0/Net/HTTP.html#method-c-Proxy

Net::HTTP::Proxy is an obsolete method, so replaced it with
Net::HTTP.new as the doc above says
  • Loading branch information
masakazutakewaka authored Jun 10, 2020
1 parent 9352cb7 commit 03bce95
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def download(required_version)

begin
File.open(download_file_name, 'wb') do |destination|
net_http.start('selenium-release.storage.googleapis.com') do |http|
net_http_start('selenium-release.storage.googleapis.com') do |http|
resp = http.request_get("/#{required_version[/(\d+\.\d+)\./, 1]}/#{download_file_name}") do |response|
total = response.content_length
progress = 0
Expand Down Expand Up @@ -111,7 +111,7 @@ def download(required_version)

def latest
require 'rexml/document'
net_http.start('selenium-release.storage.googleapis.com') do |http|
net_http_start('selenium-release.storage.googleapis.com') do |http|
versions = REXML::Document.new(http.get('/').body).root.get_elements('//Contents/Key').map do |e|
e.text[/selenium-server-standalone-(\d+\.\d+\.\d+)\.jar/, 1]
end
Expand All @@ -120,16 +120,16 @@ def latest
end
end

def net_http
def net_http_start(address, &block)
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']

if http_proxy
http_proxy = "http://#{http_proxy}" unless http_proxy.start_with?('http://')
uri = URI.parse(http_proxy)

Net::HTTP::Proxy(uri.host, uri.port)
Net::HTTP.start(address, nil, uri.host, uri.port, &block)
else
Net::HTTP
Net::HTTP.start(address, &block)
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions rb/lib/selenium/webdriver/remote/http/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ def new_http_client

proxy = URI.parse(url)

clazz = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password)
clazz.new(server_url.host, server_url.port)
Net::HTTP.new(server_url.host, server_url.port, proxy.host, proxy.port, proxy.user, proxy.password)
else
Net::HTTP.new server_url.host, server_url.port
end
Expand Down
4 changes: 2 additions & 2 deletions rb/spec/unit/selenium/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ module Selenium

it 'automatically repairs http_proxy settings that do not start with http://' do
with_env('http_proxy' => 'proxy.com') do
expect(Selenium::Server.net_http.proxy_address).to eq('proxy.com')
expect(Selenium::Server.net_http_start('example.com', &:proxy_address)).to eq('proxy.com')
end

with_env('HTTP_PROXY' => 'proxy.com') do
expect(Selenium::Server.net_http.proxy_address).to eq('proxy.com')
expect(Selenium::Server.net_http_start('example.com', &:proxy_address)).to eq('proxy.com')
end
end

Expand Down

0 comments on commit 03bce95

Please sign in to comment.