@@ -1103,7 +1103,7 @@ class << HTTP
1103
1103
# For proxy-defining arguments +p_addr+ through +p_no_proxy+,
1104
1104
# see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1105
1105
#
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 )
1107
1107
http = super address , port
1108
1108
1109
1109
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
1112
1112
http . proxy_port = @proxy_port
1113
1113
http . proxy_user = @proxy_user
1114
1114
http . proxy_pass = @proxy_pass
1115
+ http . proxy_use_ssl = @proxy_use_ssl
1115
1116
elsif p_addr == :ENV then
1116
1117
http . proxy_from_env = true
1117
1118
else
@@ -1123,6 +1124,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
1123
1124
http . proxy_port = p_port || default_port
1124
1125
http . proxy_user = p_user
1125
1126
http . proxy_pass = p_pass
1127
+ http . proxy_use_ssl = p_use_ssl
1126
1128
end
1127
1129
1128
1130
http
@@ -1158,6 +1160,7 @@ def initialize(address, port = nil) # :nodoc:
1158
1160
@proxy_port = nil
1159
1161
@proxy_user = nil
1160
1162
@proxy_pass = nil
1163
+ @proxy_use_ssl = nil
1161
1164
1162
1165
@use_ssl = false
1163
1166
@ssl_context = nil
@@ -1292,6 +1295,7 @@ def response_body_encoding=(value)
1292
1295
# Sets the proxy password;
1293
1296
# see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1294
1297
attr_writer :proxy_pass
1298
+ attr_writer :proxy_use_ssl
1295
1299
1296
1300
# Returns the IP address for the connection.
1297
1301
#
@@ -1651,7 +1655,13 @@ def connect
1651
1655
debug "opened"
1652
1656
if use_ssl?
1653
1657
if proxy?
1654
- plain_sock = BufferedIO . new ( s , read_timeout : @read_timeout ,
1658
+ if @proxy_use_ssl
1659
+ proxy_sock = OpenSSL ::SSL ::SSLSocket . new ( s )
1660
+ ssl_socket_connect ( proxy_sock , @open_timeout )
1661
+ else
1662
+ proxy_sock = s
1663
+ end
1664
+ proxy_sock = BufferedIO . new ( proxy_sock , read_timeout : @read_timeout ,
1655
1665
write_timeout : @write_timeout ,
1656
1666
continue_timeout : @continue_timeout ,
1657
1667
debug_output : @debug_output )
@@ -1662,8 +1672,8 @@ def connect
1662
1672
buf << "Proxy-Authorization: Basic #{ credential } \r \n "
1663
1673
end
1664
1674
buf << "\r \n "
1665
- plain_sock . write ( buf )
1666
- HTTPResponse . read_new ( plain_sock ) . value
1675
+ proxy_sock . write ( buf )
1676
+ HTTPResponse . read_new ( proxy_sock ) . value
1667
1677
# assuming nothing left in buffers after successful CONNECT response
1668
1678
end
1669
1679
@@ -1771,13 +1781,14 @@ def do_finish
1771
1781
@proxy_port = nil
1772
1782
@proxy_user = nil
1773
1783
@proxy_pass = nil
1784
+ @proxy_use_ssl = nil
1774
1785
1775
1786
# Creates an \HTTP proxy class which behaves like \Net::HTTP, but
1776
1787
# performs all access via the specified proxy.
1777
1788
#
1778
1789
# This class is obsolete. You may pass these same parameters directly to
1779
1790
# \Net::HTTP.new. See Net::HTTP.new for details of the arguments.
1780
- def HTTP . Proxy ( p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil ) #:nodoc:
1791
+ def HTTP . Proxy ( p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_use_ssl = nil ) #:nodoc:
1781
1792
return self unless p_addr
1782
1793
1783
1794
Class . new ( self ) {
@@ -1795,6 +1806,7 @@ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) #:nodoc:
1795
1806
1796
1807
@proxy_user = p_user
1797
1808
@proxy_pass = p_pass
1809
+ @proxy_use_ssl = p_use_ssl
1798
1810
}
1799
1811
end
1800
1812
@@ -1819,6 +1831,9 @@ def proxy_class?
1819
1831
# Returns the password for accessing the proxy, or +nil+ if none;
1820
1832
# see Net::HTTP@Proxy+Server.
1821
1833
attr_reader :proxy_pass
1834
+
1835
+ # Use SSL when talking to the proxy. If Net::HTTP does not use a proxy, nil.
1836
+ attr_reader :proxy_use_ssl
1822
1837
end
1823
1838
1824
1839
# Returns +true+ if a proxy server is defined, +false+ otherwise;
0 commit comments