|
22 | 22 |
|
23 | 23 | require 'net/protocol' |
24 | 24 | require 'uri' |
25 | | -require 'resolv' |
26 | 25 | autoload :OpenSSL, 'openssl' |
27 | 26 |
|
28 | 27 | module Net #:nodoc: |
@@ -1539,6 +1538,29 @@ def use_ssl=(flag) |
1539 | 1538 |
|
1540 | 1539 | SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc: |
1541 | 1540 |
|
| 1541 | + # Resolv::IPv4::Regex and Resolv::IPv6::Regex, copied from resolv 0.7.1 rather |
| 1542 | + # than required, so that net/http does not load a DNS resolver just to keep an |
| 1543 | + # IP address literal out of the Server Name Indication. |
| 1544 | + # https://github.com/ruby/resolv/blob/v0.7.1/lib/resolv.rb |
| 1545 | + ipv4_octet = /0|1(?:[0-9][0-9]?)?|2(?:[0-4][0-9]?|5[0-5]?|[6-9])?|[3-9][0-9]?/ |
| 1546 | + hex16 = /[0-9A-Fa-f]{1,4}/ |
| 1547 | + hex16_group = /(?:#{hex16}(?::#{hex16})*)?/ |
| 1548 | + dotted_quad = /\d+\.\d+\.\d+\.\d+/ |
| 1549 | + zone_id = /%[-0-9A-Za-z._~]+/ |
| 1550 | + |
| 1551 | + IPV4_ADDRESS = /\A(?:#{ipv4_octet})\.(?:#{ipv4_octet})\.(?:#{ipv4_octet})\.(?:#{ipv4_octet})\z/ # :nodoc: |
| 1552 | + |
| 1553 | + IPV6_ADDRESS = /\A(?: |
| 1554 | + (?:#{hex16}:){7}#{hex16} # a:b:c:d:e:f:g:h |
| 1555 | + | #{hex16_group}::#{hex16_group} # a::b |
| 1556 | + | (?:#{hex16}:){6}#{dotted_quad} # a:b:c:d:e:f:w.x.y.z |
| 1557 | + | #{hex16_group}::(?:#{hex16}:)*#{dotted_quad} # a::b:w.x.y.z |
| 1558 | + | [Ff][Ee]80(?::#{hex16}){7}#{zone_id} # fe80:b:c:d:e:f:g:h%em1 |
| 1559 | + | [Ff][Ee]80:(?:#{hex16_group}::#{hex16_group}|:#{hex16_group})?:#{hex16}#{zone_id} # fe80::b%em1 |
| 1560 | + )\z/x # :nodoc: |
| 1561 | + |
| 1562 | + private_constant :IPV4_ADDRESS, :IPV6_ADDRESS |
| 1563 | + |
1542 | 1564 | # Sets or returns the path to a CA certification file in PEM format. |
1543 | 1565 | attr_accessor :ca_file |
1544 | 1566 |
|
@@ -1738,7 +1760,7 @@ def connect |
1738 | 1760 |
|
1739 | 1761 | # Server Name Indication (SNI) RFC 3546/6066 |
1740 | 1762 | case @address |
1741 | | - when Resolv::IPv4::Regex, Resolv::IPv6::Regex |
| 1763 | + when IPV4_ADDRESS, IPV6_ADDRESS |
1742 | 1764 | # don't set SNI, as IP addresses in SNI is not valid |
1743 | 1765 | # per RFC 6066, section 3. |
1744 | 1766 |
|
|
0 commit comments