moved the matching logic of channel to its class, where it belongs

This commit is contained in:
HoneyryderChuck 2017-12-13 00:33:15 +00:00
parent 8006f5c8bc
commit 36480b8fbf
2 changed files with 9 additions and 16 deletions

View File

@ -35,23 +35,19 @@ module HTTPX
@on_response = on_response
end
def match?(uri)
ip = TCPSocket.getaddress(uri.host)
ip == @io.ip &&
uri.port == @io.port &&
uri.scheme == @uri.scheme
end
def to_io
connect
@io.to_io
end
def uri
@io.uri
end
def remote_ip
@io.ip
end
def remote_port
@io.port
end
def close(hard=false)
if pr = @parser
pr.close

View File

@ -70,11 +70,8 @@ module HTTPX
#
def bind(uri)
uri = URI(uri)
ip = TCPSocket.getaddress(uri.host)
return @channels.find do |channel|
ip == channel.remote_ip &&
uri.port == channel.remote_port &&
uri.scheme == channel.uri.scheme
channel.match?(uri)
end || begin
build_channel(uri)
end