diff options
author | Seth Vargo <sethvargo@gmail.com> | 2014-01-20 18:23:08 -0500 |
---|---|---|
committer | Seth Vargo <sethvargo@gmail.com> | 2014-01-20 18:40:09 -0500 |
commit | cbdf2e728ab025fa0b7c69aa44b4cf274aa9cd31 (patch) | |
tree | b0dbb4dc923548b5f2bb16ab71136247691250c8 | |
parent | 76e82b235b54bbbfd58af27b559e055295089492 (diff) | |
download | chef-zero-cbdf2e728ab025fa0b7c69aa44b4cf274aa9cd31.tar.gz |
Fix IPV6 support
In c3373e4, @danielsdeleo added support for IPV6, but I didn't understand
the purpose of the bracket notation. I thought they were part of the `host`,
but they are actually part of the URL. We _need_ the brackets in the URL,
but we _cannot_ have the brackets in the host.
-rw-r--r-- | lib/chef_zero/server.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index 89aa975..26ccec2 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -70,7 +70,6 @@ module ChefZero def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) - @options[:host] = "[#{@options[:host]}]" if @options[:host].include?(':') @options.freeze ChefZero::Log.level = @options[:log_level].to_sym @@ -85,12 +84,19 @@ module ChefZero include ChefZero::Endpoints # - # The URL for this Chef Zero server. + # The URL for this Chef Zero server. If the given host is an IPV6 address, + # it is escaped in brackets according to RFC-2732. + # + # @see http://www.ietf.org/rfc/rfc2732.txt RFC-2732 # # @return [String] # def url - "http://#{@options[:host]}:#{@options[:port]}" + @url ||= if @options[:host].include?(':') + "http://[#{@options[:host]}]:#{@options[:port]}" + else + "http://#{@options[:host]}:#{@options[:port]}" + end end # |