summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-11-19 14:08:34 -0800
committerdanielsdeleo <dan@opscode.com>2013-11-21 11:07:32 -0800
commit9025caf3e41b1deefcbd1d832c70100d829fdc69 (patch)
treec1e2464ae4f5c347a070d022547cb5d8e6b3e1db
parentc2466a05bc1ffca9214b06b5e357303ed0578282 (diff)
downloadchef-9025caf3e41b1deefcbd1d832c70100d829fdc69.tar.gz
Patch ruby 2.0 Net::HTTP proxy code for IPv6
Ruby 2.0 changes the way proxying is implemented in Net::HTTP such that each request will check the URI for "proxy-ness." This check will generate a URL from the given address and port without wrapping IPv6 addresses in brackets, which triggers an error in the URI library. Check for this case on startup and monkey patch the offending method if necessary.
-rw-r--r--chef/lib/chef/monkey_patches/net_http.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/chef/lib/chef/monkey_patches/net_http.rb b/chef/lib/chef/monkey_patches/net_http.rb
index ad4ba957f6..083db2216b 100644
--- a/chef/lib/chef/monkey_patches/net_http.rb
+++ b/chef/lib/chef/monkey_patches/net_http.rb
@@ -20,3 +20,37 @@ module Net
include ChefNetHTTPExceptionExtensions
end
end
+
+if Net::HTTP.instance_methods.map {|m| m.to_s}.include?("proxy_uri")
+ begin
+ # Ruby 2.0 changes the way proxy support is implemented in Net::HTTP.
+ # The implementation does not work correctly with IPv6 literals because it
+ # concatenates the address into a URI without adding square brackets for
+ # IPv6 addresses.
+ #
+ # If the bug is present, a call to Net::HTTP#proxy_uri when the host is an
+ # IPv6 address will fail by creating an invalid URI, like so:
+ #
+ # ruby -r'net/http' -e 'Net::HTTP.new("::1", 80).proxy_uri'
+ # /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/uri/generic.rb:214:in `initialize': the scheme http does not accept registry part: ::1:80 (or bad hostname?) (URI::InvalidURIError)
+ # from /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/uri/http.rb:84:in `initialize'
+ # from /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/uri/common.rb:214:in `new'
+ # from /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/uri/common.rb:214:in `parse'
+ # from /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/uri/common.rb:747:in `parse'
+ # from /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/uri/common.rb:994:in `URI'
+ # from /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/http.rb:1027:in `proxy_uri'
+ # from -e:1:in `<main>'
+ #
+ # https://bugs.ruby-lang.org/issues/9129
+ Net::HTTP.new("::1", 80).proxy_uri
+ rescue URI::InvalidURIError
+ class Net::HTTP
+
+ def proxy_uri # :nodoc:
+ ipv6_safe_addr = address.to_s.include?(":") ? "[#{address}]" : address
+ @proxy_uri ||= URI("http://#{ipv6_safe_addr}:#{port}").find_proxy
+ end
+
+ end
+ end
+end