Skip to content

Commit

Permalink
IPv6 literal support (#330)
Browse files Browse the repository at this point in the history
Apply patch from:
master...foca:ipv6_support

I added a test that checks requests localhost (::1) works.
  • Loading branch information
sdemjanenko authored Jun 1, 2020
1 parent e5fa144 commit a91c0f1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/em-http/http_client_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def set_uri(uri, path = nil, query = nil)

@uri = uri
@path = uri.path
@host = uri.host
@host = uri.hostname
@port = uri.port
@query = query

Expand Down
4 changes: 2 additions & 2 deletions lib/em-http/http_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ def connection_completed
@peer = @conn.get_peername

if @connopts.socks_proxy?
socksify(client.req.uri.host, client.req.uri.inferred_port, *@connopts.proxy[:authorization]) { start }
socksify(client.req.uri.hostname, client.req.uri.inferred_port, *@connopts.proxy[:authorization]) { start }
elsif @connopts.connect_proxy?
connectify(client.req.uri.host, client.req.uri.inferred_port, *@connopts.proxy[:authorization]) { start }
connectify(client.req.uri.hostname, client.req.uri.inferred_port, *@connopts.proxy[:authorization]) { start }
else
start
end
Expand Down
4 changes: 2 additions & 2 deletions lib/em-http/http_connection_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def initialize(uri, options)
uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
@https = uri.scheme == "https"
uri.port ||= (@https ? 443 : 80)
@tls[:sni_hostname] = uri.host
@tls[:sni_hostname] = uri.hostname

@proxy = options[:proxy] || proxy_from_env

if proxy
@host = proxy[:host]
@port = proxy[:port]
else
@host = uri.host
@host = uri.hostname
@port = uri.port
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -977,4 +977,24 @@ def failed(http=nil)
}
end
end

context "IPv6" do
it "should perform successful GET" do
EventMachine.run {
@s = StubServer.new({
response: "HTTP/1.1 200 OK\r\n\r\nHello IPv6",
port: 8091,
host: '::1',
})
http = EventMachine::HttpRequest.new('http://[::1]:8091/').get

http.errback { failed(http) }
http.callback {
http.response_header.status.should == 200
http.response.should match(/Hello IPv6/)
EventMachine.stop
}
}
end
end
end

0 comments on commit a91c0f1

Please sign in to comment.