@@ -1103,7 +1103,7 @@ class << HTTP
11031103 # For proxy-defining arguments +p_addr+ through +p_no_proxy+,
11041104 # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
11051105 #
1106- def HTTP . new ( address , port = nil , p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_no_proxy = nil )
1106+ def HTTP . new ( address , port = nil , p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_no_proxy = nil , p_use_ssl = nil )
11071107 http = super address , port
11081108
11091109 if proxy_class? then # from Net::HTTP::Proxy()
@@ -1112,6 +1112,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
11121112 http . proxy_port = @proxy_port
11131113 http . proxy_user = @proxy_user
11141114 http . proxy_pass = @proxy_pass
1115+ http . proxy_use_ssl = @proxy_use_ssl
11151116 elsif p_addr == :ENV then
11161117 http . proxy_from_env = true
11171118 else
@@ -1123,6 +1124,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
11231124 http . proxy_port = p_port || default_port
11241125 http . proxy_user = p_user
11251126 http . proxy_pass = p_pass
1127+ http . proxy_use_ssl = p_use_ssl
11261128 end
11271129
11281130 http
@@ -1190,6 +1192,7 @@ def initialize(address, port = nil) # :nodoc:
11901192 @proxy_port = nil
11911193 @proxy_user = nil
11921194 @proxy_pass = nil
1195+ @proxy_use_ssl = nil
11931196
11941197 @use_ssl = false
11951198 @ssl_context = nil
@@ -1324,6 +1327,7 @@ def response_body_encoding=(value)
13241327 # Sets the proxy password;
13251328 # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
13261329 attr_writer :proxy_pass
1330+ attr_writer :proxy_use_ssl
13271331
13281332 # Returns the IP address for the connection.
13291333 #
@@ -1668,7 +1672,13 @@ def connect
16681672 debug "opened"
16691673 if use_ssl?
16701674 if proxy?
1671- plain_sock = BufferedIO . new ( s , read_timeout : @read_timeout ,
1675+ if @proxy_use_ssl
1676+ proxy_sock = OpenSSL ::SSL ::SSLSocket . new ( s )
1677+ ssl_socket_connect ( proxy_sock , @open_timeout )
1678+ else
1679+ proxy_sock = s
1680+ end
1681+ proxy_sock = BufferedIO . new ( proxy_sock , read_timeout : @read_timeout ,
16721682 write_timeout : @write_timeout ,
16731683 continue_timeout : @continue_timeout ,
16741684 debug_output : @debug_output )
@@ -1679,8 +1689,8 @@ def connect
16791689 buf << "Proxy-Authorization: Basic #{ credential } \r \n "
16801690 end
16811691 buf << "\r \n "
1682- plain_sock . write ( buf )
1683- HTTPResponse . read_new ( plain_sock ) . value
1692+ proxy_sock . write ( buf )
1693+ HTTPResponse . read_new ( proxy_sock ) . value
16841694 # assuming nothing left in buffers after successful CONNECT response
16851695 end
16861696
@@ -1788,13 +1798,14 @@ def do_finish
17881798 @proxy_port = nil
17891799 @proxy_user = nil
17901800 @proxy_pass = nil
1801+ @proxy_use_ssl = nil
17911802
17921803 # Creates an \HTTP proxy class which behaves like \Net::HTTP, but
17931804 # performs all access via the specified proxy.
17941805 #
17951806 # This class is obsolete. You may pass these same parameters directly to
17961807 # \Net::HTTP.new. See Net::HTTP.new for details of the arguments.
1797- def HTTP . Proxy ( p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil ) #:nodoc:
1808+ def HTTP . Proxy ( p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_use_ssl = nil ) #:nodoc:
17981809 return self unless p_addr
17991810
18001811 Class . new ( self ) {
@@ -1812,6 +1823,7 @@ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) #:nodoc:
18121823
18131824 @proxy_user = p_user
18141825 @proxy_pass = p_pass
1826+ @proxy_use_ssl = p_use_ssl
18151827 }
18161828 end
18171829
@@ -1836,6 +1848,9 @@ def proxy_class?
18361848 # Returns the password for accessing the proxy, or +nil+ if none;
18371849 # see Net::HTTP@Proxy+Server.
18381850 attr_reader :proxy_pass
1851+
1852+ # Use SSL when talking to the proxy. If Net::HTTP does not use a proxy, nil.
1853+ attr_reader :proxy_use_ssl
18391854 end
18401855
18411856 # Returns +true+ if a proxy server is defined, +false+ otherwise;
0 commit comments