net-http 0.4.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/net/http.rb CHANGED
@@ -67,6 +67,8 @@ module Net #:nodoc:
67
67
  # Net::HTTP.post(uri, data)
68
68
  # params = {title: 'foo', body: 'bar', userId: 1}
69
69
  # Net::HTTP.post_form(uri, params)
70
+ # data = '{"title": "foo", "body": "bar", "userId": 1}'
71
+ # Net::HTTP.put(uri, data)
70
72
  #
71
73
  # - If performance is important, consider using sessions, which lower request overhead.
72
74
  # This {session}[rdoc-ref:Net::HTTP@Sessions] has multiple requests for
@@ -456,6 +458,10 @@ module Net #:nodoc:
456
458
  #
457
459
  # == What's Here
458
460
  #
461
+ # First, what's elsewhere. Class Net::HTTP:
462
+ #
463
+ # - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html#class-Object-label-What-27s+Here].
464
+ #
459
465
  # This is a categorized summary of methods and attributes.
460
466
  #
461
467
  # === \Net::HTTP Objects
@@ -469,8 +475,7 @@ module Net #:nodoc:
469
475
  #
470
476
  # - {::start}[rdoc-ref:Net::HTTP.start]:
471
477
  # Begins a new session in a new \Net::HTTP object.
472
- # - {#started?}[rdoc-ref:Net::HTTP#started?]
473
- # (aliased as {#active?}[rdoc-ref:Net::HTTP#active?]):
478
+ # - {#started?}[rdoc-ref:Net::HTTP#started?]:
474
479
  # Returns whether in a session.
475
480
  # - {#finish}[rdoc-ref:Net::HTTP#finish]:
476
481
  # Ends an active session.
@@ -520,6 +525,8 @@ module Net #:nodoc:
520
525
  # Sends a POST request with form data and returns a response object.
521
526
  # - {::post}[rdoc-ref:Net::HTTP.post]:
522
527
  # Sends a POST request with data and returns a response object.
528
+ # - {::put}[rdoc-ref:Net::HTTP.put]:
529
+ # Sends a PUT request with data and returns a response object.
523
530
  # - {#copy}[rdoc-ref:Net::HTTP#copy]:
524
531
  # Sends a COPY request and returns a response object.
525
532
  # - {#delete}[rdoc-ref:Net::HTTP#delete]:
@@ -548,18 +555,15 @@ module Net #:nodoc:
548
555
  # Sends a PUT request and returns a response object.
549
556
  # - {#request}[rdoc-ref:Net::HTTP#request]:
550
557
  # Sends a request and returns a response object.
551
- # - {#request_get}[rdoc-ref:Net::HTTP#request_get]
552
- # (aliased as {#get2}[rdoc-ref:Net::HTTP#get2]):
558
+ # - {#request_get}[rdoc-ref:Net::HTTP#request_get]:
553
559
  # Sends a GET request and forms a response object;
554
560
  # if a block given, calls the block with the object,
555
561
  # otherwise returns the object.
556
- # - {#request_head}[rdoc-ref:Net::HTTP#request_head]
557
- # (aliased as {#head2}[rdoc-ref:Net::HTTP#head2]):
562
+ # - {#request_head}[rdoc-ref:Net::HTTP#request_head]:
558
563
  # Sends a HEAD request and forms a response object;
559
564
  # if a block given, calls the block with the object,
560
565
  # otherwise returns the object.
561
- # - {#request_post}[rdoc-ref:Net::HTTP#request_post]
562
- # (aliased as {#post2}[rdoc-ref:Net::HTTP#post2]):
566
+ # - {#request_post}[rdoc-ref:Net::HTTP#request_post]:
563
567
  # Sends a POST request and forms a response object;
564
568
  # if a block given, calls the block with the object,
565
569
  # otherwise returns the object.
@@ -597,8 +601,7 @@ module Net #:nodoc:
597
601
  # Returns whether +self+ is a proxy class.
598
602
  # - {#proxy?}[rdoc-ref:Net::HTTP#proxy?]:
599
603
  # Returns whether +self+ has a proxy.
600
- # - {#proxy_address}[rdoc-ref:Net::HTTP#proxy_address]
601
- # (aliased as {#proxyaddr}[rdoc-ref:Net::HTTP#proxyaddr]):
604
+ # - {#proxy_address}[rdoc-ref:Net::HTTP#proxy_address]:
602
605
  # Returns the proxy address.
603
606
  # - {#proxy_from_env?}[rdoc-ref:Net::HTTP#proxy_from_env?]:
604
607
  # Returns whether the proxy is taken from an environment variable.
@@ -710,8 +713,7 @@ module Net #:nodoc:
710
713
  # === \HTTP Version
711
714
  #
712
715
  # - {::version_1_2?}[rdoc-ref:Net::HTTP.version_1_2?]
713
- # (aliased as {::is_version_1_2?}[rdoc-ref:Net::HTTP.is_version_1_2?]
714
- # and {::version_1_2}[rdoc-ref:Net::HTTP.version_1_2]):
716
+ # (aliased as {::version_1_2}[rdoc-ref:Net::HTTP.version_1_2]):
715
717
  # Returns true; retained for compatibility.
716
718
  #
717
719
  # === Debugging
@@ -722,7 +724,7 @@ module Net #:nodoc:
722
724
  class HTTP < Protocol
723
725
 
724
726
  # :stopdoc:
725
- VERSION = "0.4.1"
727
+ VERSION = "0.8.0"
726
728
  HTTPVersion = '1.1'
727
729
  begin
728
730
  require 'zlib'
@@ -889,6 +891,39 @@ module Net #:nodoc:
889
891
  }
890
892
  end
891
893
 
894
+ # Sends a PUT request to the server; returns a Net::HTTPResponse object.
895
+ #
896
+ # Argument +url+ must be a URL;
897
+ # argument +data+ must be a string:
898
+ #
899
+ # _uri = uri.dup
900
+ # _uri.path = '/posts'
901
+ # data = '{"title": "foo", "body": "bar", "userId": 1}'
902
+ # headers = {'content-type': 'application/json'}
903
+ # res = Net::HTTP.put(_uri, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true>
904
+ # puts res.body
905
+ #
906
+ # Output:
907
+ #
908
+ # {
909
+ # "title": "foo",
910
+ # "body": "bar",
911
+ # "userId": 1,
912
+ # "id": 101
913
+ # }
914
+ #
915
+ # Related:
916
+ #
917
+ # - Net::HTTP::Put: request class for \HTTP method +PUT+.
918
+ # - Net::HTTP#put: convenience method for \HTTP method +PUT+.
919
+ #
920
+ def HTTP.put(url, data, header = nil)
921
+ start(url.hostname, url.port,
922
+ :use_ssl => url.scheme == 'https' ) {|http|
923
+ http.put(url, data, header)
924
+ }
925
+ end
926
+
892
927
  #
893
928
  # \HTTP session management
894
929
  #
@@ -1062,7 +1097,7 @@ module Net #:nodoc:
1062
1097
  # For proxy-defining arguments +p_addr+ through +p_no_proxy+,
1063
1098
  # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1064
1099
  #
1065
- def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_no_proxy = nil)
1100
+ 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)
1066
1101
  http = super address, port
1067
1102
 
1068
1103
  if proxy_class? then # from Net::HTTP::Proxy()
@@ -1071,6 +1106,7 @@ module Net #:nodoc:
1071
1106
  http.proxy_port = @proxy_port
1072
1107
  http.proxy_user = @proxy_user
1073
1108
  http.proxy_pass = @proxy_pass
1109
+ http.proxy_use_ssl = @proxy_use_ssl
1074
1110
  elsif p_addr == :ENV then
1075
1111
  http.proxy_from_env = true
1076
1112
  else
@@ -1082,34 +1118,68 @@ module Net #:nodoc:
1082
1118
  http.proxy_port = p_port || default_port
1083
1119
  http.proxy_user = p_user
1084
1120
  http.proxy_pass = p_pass
1121
+ http.proxy_use_ssl = p_use_ssl
1085
1122
  end
1086
1123
 
1087
1124
  http
1088
1125
  end
1089
1126
 
1127
+ class << HTTP
1128
+ # Allows to set the default configuration that will be used
1129
+ # when creating a new connection.
1130
+ #
1131
+ # Example:
1132
+ #
1133
+ # Net::HTTP.default_configuration = {
1134
+ # read_timeout: 1,
1135
+ # write_timeout: 1
1136
+ # }
1137
+ # http = Net::HTTP.new(hostname)
1138
+ # http.open_timeout # => 60
1139
+ # http.read_timeout # => 1
1140
+ # http.write_timeout # => 1
1141
+ #
1142
+ attr_accessor :default_configuration
1143
+ end
1144
+
1090
1145
  # Creates a new \Net::HTTP object for the specified server address,
1091
1146
  # without opening the TCP connection or initializing the \HTTP session.
1092
1147
  # The +address+ should be a DNS hostname or IP address.
1093
1148
  def initialize(address, port = nil) # :nodoc:
1149
+ defaults = {
1150
+ keep_alive_timeout: 2,
1151
+ close_on_empty_response: false,
1152
+ open_timeout: 60,
1153
+ read_timeout: 60,
1154
+ write_timeout: 60,
1155
+ continue_timeout: nil,
1156
+ max_retries: 1,
1157
+ debug_output: nil,
1158
+ response_body_encoding: false,
1159
+ ignore_eof: true
1160
+ }
1161
+ options = defaults.merge(self.class.default_configuration || {})
1162
+
1094
1163
  @address = address
1095
1164
  @port = (port || HTTP.default_port)
1096
1165
  @ipaddr = nil
1097
1166
  @local_host = nil
1098
1167
  @local_port = nil
1099
1168
  @curr_http_version = HTTPVersion
1100
- @keep_alive_timeout = 2
1169
+ @keep_alive_timeout = options[:keep_alive_timeout]
1101
1170
  @last_communicated = nil
1102
- @close_on_empty_response = false
1171
+ @close_on_empty_response = options[:close_on_empty_response]
1103
1172
  @socket = nil
1104
1173
  @started = false
1105
- @open_timeout = 60
1106
- @read_timeout = 60
1107
- @write_timeout = 60
1108
- @continue_timeout = nil
1109
- @max_retries = 1
1110
- @debug_output = nil
1111
- @response_body_encoding = false
1112
- @ignore_eof = true
1174
+ @open_timeout = options[:open_timeout]
1175
+ @read_timeout = options[:read_timeout]
1176
+ @write_timeout = options[:write_timeout]
1177
+ @continue_timeout = options[:continue_timeout]
1178
+ @max_retries = options[:max_retries]
1179
+ @debug_output = options[:debug_output]
1180
+ @response_body_encoding = options[:response_body_encoding]
1181
+ @ignore_eof = options[:ignore_eof]
1182
+ @tcpsocket_supports_open_timeout = nil
1113
1183
 
1114
1184
  @proxy_from_env = false
1115
1185
  @proxy_uri = nil
@@ -1117,6 +1187,7 @@ module Net #:nodoc:
1117
1187
  @proxy_port = nil
1118
1188
  @proxy_user = nil
1119
1189
  @proxy_pass = nil
1190
+ @proxy_use_ssl = nil
1120
1191
 
1121
1192
  @use_ssl = false
1122
1193
  @ssl_context = nil
@@ -1252,6 +1323,10 @@ module Net #:nodoc:
1252
1323
  # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1253
1324
  attr_writer :proxy_pass
1254
1325
 
1326
+ # Sets wheter the proxy uses SSL;
1327
+ # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1328
+ attr_writer :proxy_use_ssl
1329
+
1255
1330
  # Returns the IP address for the connection.
1256
1331
  #
1257
1332
  # If the session has not been started,
@@ -1440,23 +1515,6 @@ module Net #:nodoc:
1440
1515
  @use_ssl = flag
1441
1516
  end
1442
1517
 
1443
- SSL_IVNAMES = [
1444
- :@ca_file,
1445
- :@ca_path,
1446
- :@cert,
1447
- :@cert_store,
1448
- :@ciphers,
1449
- :@extra_chain_cert,
1450
- :@key,
1451
- :@ssl_timeout,
1452
- :@ssl_version,
1453
- :@min_version,
1454
- :@max_version,
1455
- :@verify_callback,
1456
- :@verify_depth,
1457
- :@verify_mode,
1458
- :@verify_hostname,
1459
- ] # :nodoc:
1460
1518
  SSL_ATTRIBUTES = [
1461
1519
  :ca_file,
1462
1520
  :ca_path,
@@ -1475,6 +1533,8 @@ module Net #:nodoc:
1475
1533
  :verify_hostname,
1476
1534
  ] # :nodoc:
1477
1535
 
1536
+ SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
1537
+
1478
1538
  # Sets or returns the path to a CA certification file in PEM format.
1479
1539
  attr_accessor :ca_file
1480
1540
 
@@ -1490,11 +1550,11 @@ module Net #:nodoc:
1490
1550
  attr_accessor :cert_store
1491
1551
 
1492
1552
  # Sets or returns the available SSL ciphers.
1493
- # See {OpenSSL::SSL::SSLContext#ciphers=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-ciphers-3D].
1553
+ # See {OpenSSL::SSL::SSLContext#ciphers=}[OpenSSL::SSL::SSL::Context#ciphers=].
1494
1554
  attr_accessor :ciphers
1495
1555
 
1496
1556
  # Sets or returns the extra X509 certificates to be added to the certificate chain.
1497
- # See {OpenSSL::SSL::SSLContext#add_certificate}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-add_certificate].
1557
+ # See {OpenSSL::SSL::SSLContext#add_certificate}[OpenSSL::SSL::SSL::Context#add_certificate].
1498
1558
  attr_accessor :extra_chain_cert
1499
1559
 
1500
1560
  # Sets or returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
@@ -1504,15 +1564,15 @@ module Net #:nodoc:
1504
1564
  attr_accessor :ssl_timeout
1505
1565
 
1506
1566
  # Sets or returns the SSL version.
1507
- # See {OpenSSL::SSL::SSLContext#ssl_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-ssl_version-3D].
1567
+ # See {OpenSSL::SSL::SSLContext#ssl_version=}[OpenSSL::SSL::SSL::Context#ssl_version=].
1508
1568
  attr_accessor :ssl_version
1509
1569
 
1510
1570
  # Sets or returns the minimum SSL version.
1511
- # See {OpenSSL::SSL::SSLContext#min_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-min_version-3D].
1571
+ # See {OpenSSL::SSL::SSLContext#min_version=}[OpenSSL::SSL::SSL::Context#min_version=].
1512
1572
  attr_accessor :min_version
1513
1573
 
1514
1574
  # Sets or returns the maximum SSL version.
1515
- # See {OpenSSL::SSL::SSLContext#max_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-max_version-3D].
1575
+ # See {OpenSSL::SSL::SSLContext#max_version=}[OpenSSL::SSL::SSL::Context#max_version=].
1516
1576
  attr_accessor :max_version
1517
1577
 
1518
1578
  # Sets or returns the callback for the server certification verification.
@@ -1528,7 +1588,7 @@ module Net #:nodoc:
1528
1588
 
1529
1589
  # Sets or returns whether to verify that the server certificate is valid
1530
1590
  # for the hostname.
1531
- # See {OpenSSL::SSL::SSLContext#verify_hostname=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#attribute-i-verify_mode].
1591
+ # See {OpenSSL::SSL::SSLContext#verify_hostname=}[OpenSSL::SSL::SSL::Context#verify_hostname=].
1532
1592
  attr_accessor :verify_hostname
1533
1593
 
1534
1594
  # Returns the X509 certificate chain (an array of strings)
@@ -1576,6 +1636,21 @@ module Net #:nodoc:
1576
1636
  self
1577
1637
  end
1578
1638
 
1639
+ # Finishes the \HTTP session:
1640
+ #
1641
+ # http = Net::HTTP.new(hostname)
1642
+ # http.start
1643
+ # http.started? # => true
1644
+ # http.finish # => nil
1645
+ # http.started? # => false
1646
+ #
1647
+ # Raises IOError if not in a session.
1648
+ def finish
1649
+ raise IOError, 'HTTP session not yet started' unless started?
1650
+ do_finish
1651
+ end
1652
+
1653
+ # :stopdoc:
1579
1654
  def do_start
1580
1655
  connect
1581
1656
  @started = true
@@ -1598,19 +1673,47 @@ module Net #:nodoc:
1598
1673
  end
1599
1674
 
1600
1675
  debug "opening connection to #{conn_addr}:#{conn_port}..."
1601
- s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
1602
- begin
1603
- TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1604
- rescue => e
1605
- raise e, "Failed to open TCP connection to " +
1606
- "#{conn_addr}:#{conn_port} (#{e.message})"
1607
- end
1608
- }
1676
+ begin
1677
+ s =
1678
+ case @tcpsocket_supports_open_timeout
1679
+ when nil, true
1680
+ begin
1681
+ # Use built-in timeout in TCPSocket.open if available
1682
+ sock = TCPSocket.open(conn_addr, conn_port, @local_host, @local_port, open_timeout: @open_timeout)
1683
+ @tcpsocket_supports_open_timeout = true
1684
+ sock
1685
+ rescue ArgumentError => e
1686
+ raise if !(e.message.include?('unknown keyword: :open_timeout') || e.message.include?('wrong number of arguments (given 5, expected 2..4)'))
1687
+ @tcpsocket_supports_open_timeout = false
1688
+
1689
+ # Fallback to Timeout.timeout if TCPSocket.open does not support open_timeout
1690
+ Timeout.timeout(@open_timeout, Net::OpenTimeout) {
1691
+ TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1692
+ }
1693
+ end
1694
+ when false
1695
+ # The current Ruby is known to not support TCPSocket(open_timeout:).
1696
+ # Directly fall back to Timeout.timeout to avoid performance penalty incured by rescue.
1697
+ Timeout.timeout(@open_timeout, Net::OpenTimeout) {
1698
+ TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1699
+ }
1700
+ end
1701
+ rescue => e
1702
+ e = Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions
1703
+ raise e, "Failed to open TCP connection to " +
1704
+ "#{conn_addr}:#{conn_port} (#{e.message})"
1705
+ end
1609
1706
  s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
1610
1707
  debug "opened"
1611
1708
  if use_ssl?
1612
1709
  if proxy?
1613
- plain_sock = BufferedIO.new(s, read_timeout: @read_timeout,
1710
+ if @proxy_use_ssl
1711
+ proxy_sock = OpenSSL::SSL::SSLSocket.new(s)
1712
+ ssl_socket_connect(proxy_sock, @open_timeout)
1713
+ else
1714
+ proxy_sock = s
1715
+ end
1716
+ proxy_sock = BufferedIO.new(proxy_sock, read_timeout: @read_timeout,
1614
1717
  write_timeout: @write_timeout,
1615
1718
  continue_timeout: @continue_timeout,
1616
1719
  debug_output: @debug_output)
@@ -1621,8 +1724,8 @@ module Net #:nodoc:
1621
1724
  buf << "Proxy-Authorization: Basic #{credential}\r\n"
1622
1725
  end
1623
1726
  buf << "\r\n"
1624
- plain_sock.write(buf)
1625
- HTTPResponse.read_new(plain_sock).value
1727
+ proxy_sock.write(buf)
1728
+ HTTPResponse.read_new(proxy_sock).value
1626
1729
  # assuming nothing left in buffers after successful CONNECT response
1627
1730
  end
1628
1731
 
@@ -1696,20 +1799,6 @@ module Net #:nodoc:
1696
1799
  end
1697
1800
  private :on_connect
1698
1801
 
1699
- # Finishes the \HTTP session:
1700
- #
1701
- # http = Net::HTTP.new(hostname)
1702
- # http.start
1703
- # http.started? # => true
1704
- # http.finish # => nil
1705
- # http.started? # => false
1706
- #
1707
- # Raises IOError if not in a session.
1708
- def finish
1709
- raise IOError, 'HTTP session not yet started' unless started?
1710
- do_finish
1711
- end
1712
-
1713
1802
  def do_finish
1714
1803
  @started = false
1715
1804
  @socket.close if @socket
@@ -1730,13 +1819,14 @@ module Net #:nodoc:
1730
1819
  @proxy_port = nil
1731
1820
  @proxy_user = nil
1732
1821
  @proxy_pass = nil
1822
+ @proxy_use_ssl = nil
1733
1823
 
1734
1824
  # Creates an \HTTP proxy class which behaves like \Net::HTTP, but
1735
1825
  # performs all access via the specified proxy.
1736
1826
  #
1737
1827
  # This class is obsolete. You may pass these same parameters directly to
1738
1828
  # \Net::HTTP.new. See Net::HTTP.new for details of the arguments.
1739
- def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil) #:nodoc:
1829
+ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_use_ssl = nil) #:nodoc:
1740
1830
  return self unless p_addr
1741
1831
 
1742
1832
  Class.new(self) {
@@ -1754,9 +1844,12 @@ module Net #:nodoc:
1754
1844
 
1755
1845
  @proxy_user = p_user
1756
1846
  @proxy_pass = p_pass
1847
+ @proxy_use_ssl = p_use_ssl
1757
1848
  }
1758
1849
  end
1759
1850
 
1851
+ # :startdoc:
1852
+
1760
1853
  class << HTTP
1761
1854
  # Returns true if self is a class which was created by HTTP::Proxy.
1762
1855
  def proxy_class?
@@ -1778,6 +1871,9 @@ module Net #:nodoc:
1778
1871
  # Returns the password for accessing the proxy, or +nil+ if none;
1779
1872
  # see Net::HTTP@Proxy+Server.
1780
1873
  attr_reader :proxy_pass
1874
+
1875
+ # Use SSL when talking to the proxy. If Net::HTTP does not use a proxy, nil.
1876
+ attr_reader :proxy_use_ssl
1781
1877
  end
1782
1878
 
1783
1879
  # Returns +true+ if a proxy server is defined, +false+ otherwise;
@@ -1848,9 +1944,11 @@ module Net #:nodoc:
1848
1944
  alias proxyport proxy_port #:nodoc: obsolete
1849
1945
 
1850
1946
  private
1947
+ # :stopdoc:
1851
1948
 
1852
1949
  def unescape(value)
1853
- require 'cgi/util'
1950
+ require 'cgi/escape'
1951
+ require 'cgi/util' unless defined?(CGI::EscapeExt)
1854
1952
  CGI.unescape(value)
1855
1953
  end
1856
1954
 
@@ -1875,6 +1973,7 @@ module Net #:nodoc:
1875
1973
  path
1876
1974
  end
1877
1975
  end
1976
+ # :startdoc:
1878
1977
 
1879
1978
  #
1880
1979
  # HTTP operations
@@ -2012,6 +2111,11 @@ module Net #:nodoc:
2012
2111
  # http = Net::HTTP.new(hostname)
2013
2112
  # http.put('/todos/1', data) # => #<Net::HTTPOK 200 OK readbody=true>
2014
2113
  #
2114
+ # Related:
2115
+ #
2116
+ # - Net::HTTP::Put: request class for \HTTP method PUT.
2117
+ # - Net::HTTP.put: sends PUT request, returns response body.
2118
+ #
2015
2119
  def put(path, data, initheader = nil)
2016
2120
  request(Put.new(path, initheader), data)
2017
2121
  end
@@ -2324,6 +2428,8 @@ module Net #:nodoc:
2324
2428
  res
2325
2429
  end
2326
2430
 
2431
+ # :stopdoc:
2432
+
2327
2433
  IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
2328
2434
 
2329
2435
  def transport_request(req)
@@ -2350,7 +2456,10 @@ module Net #:nodoc:
2350
2456
  res
2351
2457
  }
2352
2458
  res.reading_body(@socket, req.response_body_permitted?) {
2353
- yield res if block_given?
2459
+ if block_given?
2460
+ count = max_retries # Don't restart in the middle of a download
2461
+ yield res
2462
+ end
2354
2463
  }
2355
2464
  rescue Net::OpenTimeout
2356
2465
  raise
@@ -2478,6 +2587,11 @@ module Net #:nodoc:
2478
2587
  alias_method :D, :debug
2479
2588
  end
2480
2589
 
2590
+ # for backward compatibility until Ruby 4.0
2591
+ # https://bugs.ruby-lang.org/issues/20900
2592
+ # https://github.com/bblimke/webmock/pull/1081
2593
+ HTTPSession = HTTP
2594
+ deprecate_constant :HTTPSession
2481
2595
  end
2482
2596
 
2483
2597
  require_relative 'http/exceptions'
@@ -2492,5 +2606,3 @@ require_relative 'http/response'
2492
2606
  require_relative 'http/responses'
2493
2607
 
2494
2608
  require_relative 'http/proxy_delta'
2495
-
2496
- require_relative 'http/backward'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NARUSE, Yui
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-01-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: uri
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
18
+ version: 0.11.1
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '0'
25
+ version: 0.11.1
27
26
  description: HTTP client api for Ruby.
28
27
  email:
29
28
  - naruse@airemix.jp
@@ -31,16 +30,13 @@ executables: []
31
30
  extensions: []
32
31
  extra_rdoc_files: []
33
32
  files:
34
- - Gemfile
35
- - LICENSE.txt
33
+ - ".document"
34
+ - BSDL
35
+ - COPYING
36
36
  - README.md
37
- - Rakefile
38
- - bin/console
39
- - bin/setup
40
37
  - doc/net-http/examples.rdoc
41
38
  - doc/net-http/included_getters.rdoc
42
39
  - lib/net/http.rb
43
- - lib/net/http/backward.rb
44
40
  - lib/net/http/exceptions.rb
45
41
  - lib/net/http/generic_request.rb
46
42
  - lib/net/http/header.rb
@@ -51,15 +47,14 @@ files:
51
47
  - lib/net/http/responses.rb
52
48
  - lib/net/http/status.rb
53
49
  - lib/net/https.rb
54
- - net-http.gemspec
55
50
  homepage: https://github.com/ruby/net-http
56
51
  licenses:
57
52
  - Ruby
58
53
  - BSD-2-Clause
59
54
  metadata:
55
+ changelog_uri: https://github.com/ruby/net-http/releases
60
56
  homepage_uri: https://github.com/ruby/net-http
61
57
  source_code_uri: https://github.com/ruby/net-http
62
- post_install_message:
63
58
  rdoc_options: []
64
59
  require_paths:
65
60
  - lib
@@ -67,15 +62,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
62
  requirements:
68
63
  - - ">="
69
64
  - !ruby/object:Gem::Version
70
- version: 2.6.0
65
+ version: 2.7.0
71
66
  required_rubygems_version: !ruby/object:Gem::Requirement
72
67
  requirements:
73
68
  - - ">="
74
69
  - !ruby/object:Gem::Version
75
70
  version: '0'
76
71
  requirements: []
77
- rubygems_version: 3.6.0.dev
78
- signing_key:
72
+ rubygems_version: 3.6.9
79
73
  specification_version: 4
80
74
  summary: HTTP client api for Ruby.
81
75
  test_files: []
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem "rake"
6
- gem "test-unit"
7
- gem "test-unit-ruby-core"
8
- gem "webrick"
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test/lib"
6
- t.ruby_opts << "-rhelper"
7
- t.test_files = FileList["test/**/test_*.rb"]
8
- end
9
-
10
- task :default => :test
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "net/http"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here