@@ -1066,7 +1066,7 @@ class << HTTP
1066
1066
# For proxy-defining arguments +p_addr+ through +p_no_proxy+,
1067
1067
# see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1068
1068
#
1069
- def HTTP . new ( address , port = nil , p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_no_proxy = nil )
1069
+ 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 )
1070
1070
http = super address , port
1071
1071
1072
1072
if proxy_class? then # from Net::HTTP::Proxy()
@@ -1075,6 +1075,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
1075
1075
http . proxy_port = @proxy_port
1076
1076
http . proxy_user = @proxy_user
1077
1077
http . proxy_pass = @proxy_pass
1078
+ http . proxy_use_ssl = @proxy_use_ssl
1078
1079
elsif p_addr == :ENV then
1079
1080
http . proxy_from_env = true
1080
1081
else
@@ -1086,6 +1087,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
1086
1087
http . proxy_port = p_port || default_port
1087
1088
http . proxy_user = p_user
1088
1089
http . proxy_pass = p_pass
1090
+ http . proxy_use_ssl = p_use_ssl
1089
1091
end
1090
1092
1091
1093
http
@@ -1121,6 +1123,7 @@ def initialize(address, port = nil) # :nodoc:
1121
1123
@proxy_port = nil
1122
1124
@proxy_user = nil
1123
1125
@proxy_pass = nil
1126
+ @proxy_use_ssl = nil
1124
1127
1125
1128
@use_ssl = false
1126
1129
@ssl_context = nil
@@ -1255,6 +1258,7 @@ def response_body_encoding=(value)
1255
1258
# Sets the proxy password;
1256
1259
# see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1257
1260
attr_writer :proxy_pass
1261
+ attr_writer :proxy_use_ssl
1258
1262
1259
1263
# Returns the IP address for the connection.
1260
1264
#
@@ -1614,7 +1618,13 @@ def connect
1614
1618
debug "opened"
1615
1619
if use_ssl?
1616
1620
if proxy?
1617
- plain_sock = BufferedIO . new ( s , read_timeout : @read_timeout ,
1621
+ if @proxy_use_ssl
1622
+ proxy_sock = OpenSSL ::SSL ::SSLSocket . new ( s )
1623
+ ssl_socket_connect ( proxy_sock , @open_timeout )
1624
+ else
1625
+ proxy_sock = s
1626
+ end
1627
+ proxy_sock = BufferedIO . new ( proxy_sock , read_timeout : @read_timeout ,
1618
1628
write_timeout : @write_timeout ,
1619
1629
continue_timeout : @continue_timeout ,
1620
1630
debug_output : @debug_output )
@@ -1625,8 +1635,8 @@ def connect
1625
1635
buf << "Proxy-Authorization: Basic #{ credential } \r \n "
1626
1636
end
1627
1637
buf << "\r \n "
1628
- plain_sock . write ( buf )
1629
- HTTPResponse . read_new ( plain_sock ) . value
1638
+ proxy_sock . write ( buf )
1639
+ HTTPResponse . read_new ( proxy_sock ) . value
1630
1640
# assuming nothing left in buffers after successful CONNECT response
1631
1641
end
1632
1642
@@ -1734,13 +1744,14 @@ def do_finish
1734
1744
@proxy_port = nil
1735
1745
@proxy_user = nil
1736
1746
@proxy_pass = nil
1747
+ @proxy_use_ssl = nil
1737
1748
1738
1749
# Creates an \HTTP proxy class which behaves like \Net::HTTP, but
1739
1750
# performs all access via the specified proxy.
1740
1751
#
1741
1752
# This class is obsolete. You may pass these same parameters directly to
1742
1753
# \Net::HTTP.new. See Net::HTTP.new for details of the arguments.
1743
- def HTTP . Proxy ( p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil ) #:nodoc:
1754
+ def HTTP . Proxy ( p_addr = :ENV , p_port = nil , p_user = nil , p_pass = nil , p_use_ssl = nil ) #:nodoc:
1744
1755
return self unless p_addr
1745
1756
1746
1757
Class . new ( self ) {
@@ -1758,6 +1769,7 @@ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) #:nodoc:
1758
1769
1759
1770
@proxy_user = p_user
1760
1771
@proxy_pass = p_pass
1772
+ @proxy_use_ssl = p_use_ssl
1761
1773
}
1762
1774
end
1763
1775
@@ -1782,6 +1794,9 @@ def proxy_class?
1782
1794
# Returns the password for accessing the proxy, or +nil+ if none;
1783
1795
# see Net::HTTP@Proxy+Server.
1784
1796
attr_reader :proxy_pass
1797
+
1798
+ # Use SSL when talking to the proxy. If Net::HTTP does not use a proxy, nil.
1799
+ attr_reader :proxy_use_ssl
1785
1800
end
1786
1801
1787
1802
# Returns +true+ if a proxy server is defined, +false+ otherwise;
0 commit comments