net-http 0.8.0 → 0.9.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/.document +1 -0
  3. data/lib/net/http.rb +29 -29
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6aa488199745a574db471b279c8cbb4b46cd5dded0308bd5888f0cd9c08d5102
4
- data.tar.gz: d9804849a6cff66145baf7d6557ca5845ba8777d08acf940e431b11a8c5266d9
3
+ metadata.gz: ad9408074d86908c8284d26a13f9ba35d86948726c5e42ce453d40639be9d255
4
+ data.tar.gz: b23103da88f3b5cf36274fb39b07e6889c86fbe6e9abf4cb86ed6bc2c9ce9448
5
5
  SHA512:
6
- metadata.gz: d06f7fe540c1fae1b1d73b6b029c6e9b176073cdcf267b5b6b5b98095dd14d9cf53fd406b7cb1d854dbf9e31a8ff52fde927442f6f8250194df4166a00476e59
7
- data.tar.gz: 3583aa361d6c121814bf3092cd1c314943774009564603452d0b0f17d9f0f35b3a7841ed02806fae131f0c85edc3dbcbe20938f010ac352fc267bfa4b36e0ebe
6
+ metadata.gz: 5448ae667eff55826562b25f79a8f2e2991a79e1a763d1695429286b59e7e1ef25ffe2c22d9320dcf112daca3571112c7baae4a34c1b43caed6b0a944974c089
7
+ data.tar.gz: 7679a6cf608155d9dabb09a9ed969deddb315662d220087fb80ba2b4e6f9d8519c714c501048b5c55a48625bb013313435461813197c63f0de6aed4dbabd68dc
data/.document CHANGED
@@ -1,4 +1,5 @@
1
1
  BSDL
2
2
  COPYING
3
3
  README.md
4
+ doc/
4
5
  lib/
data/lib/net/http.rb CHANGED
@@ -724,7 +724,7 @@ module Net #:nodoc:
724
724
  class HTTP < Protocol
725
725
 
726
726
  # :stopdoc:
727
- VERSION = "0.8.0"
727
+ VERSION = "0.9.1"
728
728
  HTTPVersion = '1.1'
729
729
  begin
730
730
  require 'zlib'
@@ -1323,7 +1323,7 @@ module Net #:nodoc:
1323
1323
  # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1324
1324
  attr_writer :proxy_pass
1325
1325
 
1326
- # Sets wheter the proxy uses SSL;
1326
+ # Sets whether the proxy uses SSL;
1327
1327
  # see {Proxy Server}[rdoc-ref:Net::HTTP@Proxy+Server].
1328
1328
  attr_writer :proxy_use_ssl
1329
1329
 
@@ -1531,7 +1531,7 @@ module Net #:nodoc:
1531
1531
  :verify_depth,
1532
1532
  :verify_mode,
1533
1533
  :verify_hostname,
1534
- ] # :nodoc:
1534
+ ].freeze # :nodoc:
1535
1535
 
1536
1536
  SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
1537
1537
 
@@ -1674,32 +1674,11 @@ module Net #:nodoc:
1674
1674
 
1675
1675
  debug "opening connection to #{conn_addr}:#{conn_port}..."
1676
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
1677
+ s = timeouted_connect(conn_addr, conn_port)
1701
1678
  rescue => e
1702
- e = Net::OpenTimeout.new(e) if e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions
1679
+ if (defined?(IO::TimeoutError) && e.is_a?(IO::TimeoutError)) || e.is_a?(Errno::ETIMEDOUT) # for compatibility with previous versions
1680
+ e = Net::OpenTimeout.new(e)
1681
+ end
1703
1682
  raise e, "Failed to open TCP connection to " +
1704
1683
  "#{conn_addr}:#{conn_port} (#{e.message})"
1705
1684
  end
@@ -1795,6 +1774,27 @@ module Net #:nodoc:
1795
1774
  end
1796
1775
  private :connect
1797
1776
 
1777
+ tcp_socket_parameters = TCPSocket.instance_method(:initialize).parameters
1778
+ TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT = if tcp_socket_parameters != [[:rest]]
1779
+ tcp_socket_parameters.include?([:key, :open_timeout])
1780
+ else
1781
+ # Use Socket.tcp to find out since there is no parameters information for TCPSocket#initialize
1782
+ # See discussion in https://github.com/ruby/net-http/pull/224
1783
+ Socket.method(:tcp).parameters.include?([:key, :open_timeout])
1784
+ end
1785
+ private_constant :TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
1786
+
1787
+ def timeouted_connect(conn_addr, conn_port)
1788
+ if TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
1789
+ TCPSocket.open(conn_addr, conn_port, @local_host, @local_port, open_timeout: @open_timeout)
1790
+ else
1791
+ Timeout.timeout(@open_timeout, Net::OpenTimeout) {
1792
+ TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1793
+ }
1794
+ end
1795
+ end
1796
+ private :timeouted_connect
1797
+
1798
1798
  def on_connect
1799
1799
  end
1800
1800
  private :on_connect
@@ -2430,7 +2430,7 @@ module Net #:nodoc:
2430
2430
 
2431
2431
  # :stopdoc:
2432
2432
 
2433
- IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
2433
+ IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/.freeze # :nodoc:
2434
2434
 
2435
2435
  def transport_request(req)
2436
2436
  count = 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NARUSE, Yui