mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
matching channel against all IP addresses for the hostname; prefering
Resolv.getaddress, despite IPv4 preference (there is some inconsistency with IPv6 addresses using TCPSocket.getaddress)
This commit is contained in:
parent
278c5a4e26
commit
f411294042
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "resolv"
|
||||
require "forwardable"
|
||||
require "httpx/io"
|
||||
require "httpx/buffer"
|
||||
@ -68,13 +69,13 @@ module HTTPX
|
||||
end
|
||||
|
||||
def match?(uri)
|
||||
ip = begin
|
||||
TCPSocket.getaddress(uri.host)
|
||||
rescue StandardError
|
||||
uri.host
|
||||
end
|
||||
ips = begin
|
||||
Resolv.getaddresses(uri.host)
|
||||
rescue StandardError
|
||||
[uri.host]
|
||||
end
|
||||
|
||||
ip == @io.ip &&
|
||||
ips.include?(@io.ip) &&
|
||||
uri.port == @io.port &&
|
||||
uri.scheme == @io.scheme
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "resolv"
|
||||
require "socket"
|
||||
require "openssl"
|
||||
require "ipaddr"
|
||||
@ -19,7 +20,7 @@ module HTTPX
|
||||
if @options.io
|
||||
@io = case @options.io
|
||||
when Hash
|
||||
@ip = TCPSocket.getaddress(hostname)
|
||||
@ip = Resolv.getaddress(@hostname)
|
||||
@options.io[@ip] || @options.io["#{@ip}:#{@port}"]
|
||||
else
|
||||
@ip = hostname
|
||||
@ -30,7 +31,7 @@ module HTTPX
|
||||
@state = :connected
|
||||
end
|
||||
else
|
||||
@ip = TCPSocket.getaddress(hostname)
|
||||
@ip = Resolv.getaddress(@hostname)
|
||||
end
|
||||
@io ||= build_socket
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user