-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow HTTP::Client to use ipv6 addresses #6147
Changes from 1 commit
7f478a7
7ac9d1c
d0f13d3
a768ccd
9430f07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -651,7 +651,11 @@ class HTTP::Client | |
socket = @socket | ||
return socket if socket | ||
|
||
socket = TCPSocket.new @host, @port, @dns_timeout, @connect_timeout | ||
# URI host may have ipv6 enclosed by brackets and is fine according to | ||
# rfc3986. The host http header must contains the brackets, ie: the same | ||
# value as returned by URI#host | ||
ip_host = @host[0] == '[' && @host[-1] == ']' ? @host[1..-2] : @host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this line should be automatic. The glue code to support ipv6 should be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both Ruby and Go expose a |
||
socket = TCPSocket.new ip_host, @port, @dns_timeout, @connect_timeout | ||
socket.read_timeout = @read_timeout if @read_timeout | ||
socket.sync = false | ||
@socket = socket | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@host.starts_with?('[') && @host.ends_with?(']')
is x2 faster.@host.lstrip.rstrip
is said to be 7x than@host[1..-2]
. I wonder if adding a method to strip both at the start and at the end can make sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats because
lstrip
doesn't do what you want here? i.e. it doesn't do anything so of course it's faster.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.lchop('[').rchop(']')
should be shorter here though. Surely the same speed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the mistake, I confuse the two. Change
strip
tochop
to havelchop.rchop
With chops the program is slower