net-http icon indicating copy to clipboard operation
net-http copied to clipboard

Broken compatibility with resolv-replace

Open Touchstone117 opened this issue 3 years ago • 1 comments

Hey,

I think I've found an issue introduced with the change in #10.

Changing from TCPSocket.open to Socket.tcp seems to break the functionality of resolv-replace.

Not sure if this was a by design change and if not if the right place for a fix is here or in resolv-replace itself.

Thanks

A test demonstrating the issue:

gem 'net-http', '0.2.0' # Fails
# gem 'net-http', '0.1.0' # Works
require 'net/http'
require 'resolv-replace'

fake_host = 'not.a.host'

hosts_file_name = 'hosts_file'

hosts_file = "#{Resolv.getaddress('google.com')} #{fake_host}"
File.write(hosts_file_name, hosts_file)

hosts_resolver = Resolv::Hosts.new(hosts_file_name)

dns_resolver = Resolv::DNS.new

Resolv::DefaultResolver.replace_resolvers([hosts_resolver, dns_resolver])

puts Net::HTTP.get(URI("http://#{fake_host}"))

Touchstone117 avatar Mar 14 '22 21:03 Touchstone117

That sounds more like resolv-replace that should be updated to also patch Scoket.tcp https://github.com/ruby/resolv-replace/blob/master/lib/resolv-replace.rb

byroot avatar Apr 29 '22 16:04 byroot