lib/httparty/connection_adapter.rb in httparty-0.9.0 vs lib/httparty/connection_adapter.rb in httparty-0.10.0
- old
+ new
@@ -45,10 +45,14 @@
# * :+ssl_ca_file+: see HTTParty::ClassMethods.ssl_ca_file.
# * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
# * :+connection_adapter_options+: contains the hash your passed to HTTParty.connection_adapter when you configured your connection adapter
class ConnectionAdapter
+ # Private: Regex used to strip brackets from IPv6 URIs.
+ StripIpv6BracketsRegex = /\A\[(.*)\]\z/
+
+ # Public
def self.call(uri, options)
new(uri, options).connection
end
attr_reader :uri, :options
@@ -59,11 +63,12 @@
@uri = uri
@options = options
end
def connection
- http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass])
+ host = clean_host(uri.host)
+ http = Net::HTTP.new(host, uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass])
http.use_ssl = ssl_implied?(uri)
attach_ssl_certificates(http, options)
@@ -74,13 +79,26 @@
if options[:debug_output]
http.set_debug_output(options[:debug_output])
end
+ if options[:ciphers]
+ http.ciphers = options[:ciphers]
+ end
+
return http
end
private
+
+ def clean_host(host)
+ strip_ipv6_brackets(host)
+ end
+
+ def strip_ipv6_brackets(host)
+ StripIpv6BracketsRegex =~ host ? $1 : host
+ end
+
def ssl_implied?(uri)
uri.port == 443 || uri.instance_of?(URI::HTTPS)
end
def attach_ssl_certificates(http, options)