net-http-persistent 2.9.4 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 21b9c2d72e25672250e7d4544bed635d05a583cd
4
- data.tar.gz: 8baa746d3b463cc46282e93e1c95fea48ce34de7
2
+ SHA256:
3
+ metadata.gz: 9123e98741595dbcc1c9a9713ecdcfb517597dc52791dc546bd868c31cbe88d0
4
+ data.tar.gz: 462f4ae1dd63c8776ac18e3eab2b8e4c43e65d906722086a670d5ae3b764eb2b
5
5
  SHA512:
6
- metadata.gz: 34d31b4bb74a92791b8091bec2e098935440b522a22a00cf189a7d48652415a4729496758c30af51ce38cd1c227b3414040cb3396b348dcc355634f5fb1d012d
7
- data.tar.gz: 6afc70cd26e21e4d7fbce7d5531543ba55df0da22dd2b4ac5f697b34290f567167afc3a76a98fd7faa351e539f94cf1d2dae0295f0840036d482a6537bd0271f
6
+ metadata.gz: 45e3ea77d23e8c9829bba490c61546b71a221194cf8106bbb32ad746408283df04923649aef952d7317f06475a0a5466b19376c7a38e8b62490d65f24b6031cf
7
+ data.tar.gz: e46564075c2d655e258c5fd9ff3c45843b48c5bd6d8c5f80fe84450a36e7ac5811d0f97b5e8223277c2b607e7259df70e1e331c372e12a4bd33efec0e555e743
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # -*- ruby -*-
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~>13.0"
8
+ gem "minitest", "~>5.15", :group => [:development, :test]
9
+ gem "rdoc", ">=4.0", "<7", :group => [:development, :test]
10
+ gem "rake-manifest", "~>0.2"
11
+
12
+ gem 'net-http-pipeline', '~> 1.0' if ENV['CI_MATRIX'] == 'pipeline'
13
+
14
+ # vim: syntax=ruby
data/History.txt CHANGED
@@ -1,3 +1,110 @@
1
+ === 4.0.2 / 2023-03-29
2
+
3
+ Bug fixes:
4
+
5
+ * Fix compatibility with `connection_pool 2.4+`
6
+
7
+ === 4.0.1 / 2021-01-12
8
+
9
+ Bug fixes:
10
+
11
+ * Loosen Ruby version requirement so Ruby 3.0 will work.
12
+
13
+ === 4.0.0 / 2020-04-30
14
+
15
+ Breaking changes:
16
+
17
+ * Removed built-in support for retrying failed requests as Net::HTTP has this
18
+ built-in for all supported versions. Pull request #100 by Michael Grosser.
19
+ * Dropped support for EoL ruby versions (< 2.4). Future feature releases may
20
+ drop support for ruby versions that are at end-of-life or in security-only
21
+ maintenance mode with any release. Pull request #113 by David Rodríguez
22
+
23
+ New features:
24
+
25
+ * Added Net::HTTP::Persistent#max_retries= to configure the number of retries
26
+ performed on a request for ruby versions that support it (2.5+).
27
+ * URI-ness is determined through #respond_to? to allow compatibility with
28
+ Addressable::URI. Pull request #67 by Ryan McKern.
29
+ * Use require_relative to reduce patch burden for vendored versions. Pull
30
+ Request #106 by David Rodríguez
31
+
32
+ Bug fixes:
33
+
34
+ * Stop wasting a connection when the keep-alive timeout is less than the idle
35
+ timeout. Pull request #115 by Yap Sok Ann.
36
+ * Improved use of URI#hostname for IPv6 connections. Pull request #76 by
37
+ Tomas Koutsky.
38
+ * Improved check for Process::RLIMIT_NOFILE support. Pull request #109 by Vít
39
+ Ondruch.
40
+ * Fix namespace in comments for escape/unescape wrappers. Pull request #114
41
+ by David Rodríguez.
42
+ * Fix History.txt timestamp for 3.0.0 release. Pull request #107 by Joe Van
43
+ Dyk.
44
+ * Fix link to PR #98 in 3.1.0 release notes. Pull request #110 by Justin
45
+ Reid.
46
+
47
+ Other:
48
+
49
+ * Updated Net::HTTP::Persistent#reconnect documentation to indicate that all
50
+ connections are reset. Issue #117 by Taisuke Miyazaki.
51
+
52
+ === 3.1.0 / 2019-07-24
53
+
54
+ New features:
55
+ * Support ruby 2.6 Net::HTTP#write_timeout=. Pull request #99 by Víctor
56
+ Roldán Betancort.
57
+ * Support setting TLS min/max version. Pull request #94 by Bart.
58
+
59
+ Bug fixes:
60
+ * Reduce potential for memory leak through Hash default proc bindings. Pull
61
+ request #64 by Dominic Metzger.
62
+ * Test proxy auto detection from no_proxy in ENV. Pull request #60 by
63
+ HINOHARA Hiroshi.
64
+ * Add missing timestamp for 3.0 release. Pull request #78 by Joe Van Dyk.
65
+ * Support IPv6 URLs in proxy checks. Pull request #82 by Nicolás Sanguinetti.
66
+ * Use Net::HTTPGenericRequest#method to check idempotence for improved
67
+ compatibility. Pull request #83 by Fotos Georgiadis.
68
+ * Run net-http-pipeline tests in travis. Pull request #86 by T.J. Schuck.
69
+ * Correct +no_proxy+ support to override Net::HTTP proxy fallback. Pull
70
+ request #88 by Jared Kauppila.
71
+ * Mitigate memory leak when combined with faraday. Pull request #105 by Yohei
72
+ Kitamura.
73
+ * Set default connection pool size for Windows. Pull request #90 by Jared
74
+ Kauppila.
75
+ * Fix missing +name:+ argument in documentation. Pull requests #85 by T.J.
76
+ Schuck, #84 by James White.
77
+ * Fix memory leak from connection pooling. Pull request #98 by Aaron
78
+ Patterson.
79
+ * Update tests for minitest assert_equal deprecation. Pull request #92 by
80
+ Olle Jonsson.
81
+ * Fix typo in Net::HTTP::Persistent#pipeline. Pull request #91 by Kazuma
82
+ Furuhashi.
83
+
84
+ Other:
85
+ * Added bundler hoe plugin. Pull request #103 by Michael Grosser.
86
+ * Updated ruby versions in Travis CI. Pull request #93 by Olle Jonsson. Pull
87
+ request #103 by Michael Grosser.
88
+
89
+ === 3.0 / 2016-10-05
90
+
91
+ Breaking changes:
92
+
93
+ * No longer supports ruby 2.0 and earlier
94
+ * Net::HTTP::Persistent::new now uses keyword arguments for +name+ and
95
+ +proxy+.
96
+ * Removed #max_age, use #expired?
97
+
98
+ New features:
99
+
100
+ * Uses connection_pool to manage all connections for a Net::HTTP::Persistent
101
+ instance.
102
+
103
+ Bug fixes:
104
+
105
+ * Add missing SSL options ca_path, ciphers, ssl_timeout, verify_depth.
106
+ Issue #63 by Johnneylee Jack Rollins.
107
+
1
108
  === 2.9.4 / 2014-02-10
2
109
 
3
110
  * Bug fixes
data/Manifest.txt CHANGED
@@ -1,11 +1,13 @@
1
1
  .autotest
2
2
  .gemtest
3
+ Gemfile
3
4
  History.txt
4
5
  Manifest.txt
5
6
  README.rdoc
6
7
  Rakefile
7
- lib/net/http/faster.rb
8
8
  lib/net/http/persistent.rb
9
- lib/net/http/persistent/ssl_reuse.rb
9
+ lib/net/http/persistent/connection.rb
10
+ lib/net/http/persistent/pool.rb
11
+ lib/net/http/persistent/timed_stack_multi.rb
10
12
  test/test_net_http_persistent.rb
11
- test/test_net_http_persistent_ssl_reuse.rb
13
+ test/test_net_http_persistent_timed_stack_multi.rb
data/README.rdoc CHANGED
@@ -1,27 +1,27 @@
1
1
  = net-http-persistent
2
2
 
3
- * http://docs.seattlerb.org/net-http-persistent
4
- * https://github.com/drbrain/net-http-persistent
3
+ home :: https://github.com/drbrain/net-http-persistent
4
+ rdoc :: https://rdoc.info/gems/net-http-persistent
5
5
 
6
6
  == DESCRIPTION:
7
7
 
8
- Manages persistent connections using Net::HTTP plus a speed fix for Ruby 1.8.
9
- It's thread-safe too!
8
+ Manages persistent connections using Net::HTTP including a thread pool for
9
+ connecting to multiple hosts.
10
10
 
11
11
  Using persistent HTTP connections can dramatically increase the speed of HTTP.
12
12
  Creating a new HTTP connection for every request involves an extra TCP
13
13
  round-trip and causes TCP congestion avoidance negotiation to start over.
14
14
 
15
15
  Net::HTTP supports persistent connections with some API methods but does not
16
- handle reconnection gracefully. Net::HTTP::Persistent supports reconnection
17
- and retry according to RFC 2616.
16
+ make setting up a single persistent connection or managing multiple
17
+ connections easy. Net::HTTP::Persistent wraps Net::HTTP and allows you to
18
+ focus on how to make HTTP requests.
18
19
 
19
20
  == FEATURES/PROBLEMS:
20
21
 
21
- * Supports SSL
22
+ * Supports TLS with secure defaults
22
23
  * Thread-safe
23
24
  * Pure ruby
24
- * Timeout-less speed boost for Ruby 1.8 (by Aaron Patterson)
25
25
 
26
26
  == SYNOPSIS
27
27
 
@@ -32,7 +32,7 @@ connection is kept alive between requests:
32
32
 
33
33
  uri = URI 'http://example.com/awesome/web/service'
34
34
 
35
- http = Net::HTTP::Persistent.new 'my_app_name'
35
+ http = Net::HTTP::Persistent.new name: 'my_app_name'
36
36
 
37
37
  # perform a GET
38
38
  response = http.request uri
@@ -60,7 +60,7 @@ including SSL connection verification, header handling and tunable options.
60
60
 
61
61
  (The MIT License)
62
62
 
63
- Copyright (c) 2010 Eric Hodel, Aaron Patterson
63
+ Copyright (c) Eric Hodel, Aaron Patterson
64
64
 
65
65
  Permission is hereby granted, free of charge, to any person obtaining
66
66
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,24 +1,25 @@
1
1
  # -*- ruby -*-
2
2
 
3
- require 'rubygems'
4
- require 'hoe'
5
-
6
- Hoe.plugin :git
7
- Hoe.plugin :minitest
8
- Hoe.plugin :travis
9
-
10
- Hoe.spec 'net-http-persistent' do
11
- developer 'Eric Hodel', 'drbrain@segment7.net'
12
-
13
- self.readme_file = 'README.rdoc'
14
- self.extra_rdoc_files += Dir['*.rdoc']
15
-
16
- license 'MIT'
17
-
18
- rdoc_locations <<
19
- 'docs.seattlerb.org:/data/www/docs.seattlerb.org/net-http-persistent/'
20
-
21
- dependency 'minitest', '~> 5.2', :development
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new
8
+
9
+ require "rake/manifest"
10
+
11
+ Rake::Manifest::Task.new do |t|
12
+ t.patterns = [
13
+ ".autotest",
14
+ ".gemtest",
15
+ ".travis.yml",
16
+ "Gemfile",
17
+ "History.txt",
18
+ "Manifest.txt",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "{test,lib}/**/*"
22
+ ]
22
23
  end
23
24
 
24
25
  # vim: syntax=Ruby
@@ -0,0 +1,41 @@
1
+ ##
2
+ # A Net::HTTP connection wrapper that holds extra information for managing the
3
+ # connection's lifetime.
4
+
5
+ class Net::HTTP::Persistent::Connection # :nodoc:
6
+
7
+ attr_accessor :http
8
+
9
+ attr_accessor :last_use
10
+
11
+ attr_accessor :requests
12
+
13
+ attr_accessor :ssl_generation
14
+
15
+ def initialize http_class, http_args, ssl_generation
16
+ @http = http_class.new(*http_args)
17
+ @ssl_generation = ssl_generation
18
+
19
+ reset
20
+ end
21
+
22
+ def finish
23
+ @http.finish
24
+ rescue IOError
25
+ ensure
26
+ reset
27
+ end
28
+ alias_method :close, :finish
29
+
30
+ def reset
31
+ @last_use = Net::HTTP::Persistent::EPOCH
32
+ @requests = 0
33
+ end
34
+
35
+ def ressl ssl_generation
36
+ @ssl_generation = ssl_generation
37
+
38
+ finish
39
+ end
40
+
41
+ end
@@ -0,0 +1,65 @@
1
+ class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
2
+
3
+ attr_reader :available # :nodoc:
4
+ attr_reader :key # :nodoc:
5
+
6
+ def initialize(options = {}, &block)
7
+ super
8
+
9
+ @available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
10
+ @key = "current-#{@available.object_id}"
11
+ end
12
+
13
+ def checkin net_http_args
14
+ if net_http_args.is_a?(Hash) && net_http_args.size == 1 && net_http_args[:force]
15
+ # ConnectionPool 2.4+ calls `checkin(force: true)` after fork.
16
+ # When this happens, we should remove all connections from Thread.current
17
+ if stacks = Thread.current[@key]
18
+ stacks.each do |http_args, connections|
19
+ connections.each do |conn|
20
+ @available.push conn, connection_args: http_args
21
+ end
22
+ connections.clear
23
+ end
24
+ end
25
+ else
26
+ stack = Thread.current[@key][net_http_args] ||= []
27
+
28
+ raise ConnectionPool::Error, 'no connections are checked out' if
29
+ stack.empty?
30
+
31
+ conn = stack.pop
32
+
33
+ if stack.empty?
34
+ @available.push conn, connection_args: net_http_args
35
+
36
+ Thread.current[@key].delete(net_http_args)
37
+ Thread.current[@key] = nil if Thread.current[@key].empty?
38
+ end
39
+ end
40
+ nil
41
+ end
42
+
43
+ def checkout net_http_args
44
+ stacks = Thread.current[@key] ||= {}
45
+ stack = stacks[net_http_args] ||= []
46
+
47
+ if stack.empty? then
48
+ conn = @available.pop connection_args: net_http_args
49
+ else
50
+ conn = stack.last
51
+ end
52
+
53
+ stack.push conn
54
+
55
+ conn
56
+ end
57
+
58
+ def shutdown
59
+ Thread.current[@key] = nil
60
+ super
61
+ end
62
+ end
63
+
64
+ require_relative 'timed_stack_multi'
65
+
@@ -0,0 +1,79 @@
1
+ class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:
2
+
3
+ ##
4
+ # Returns a new hash that has arrays for keys
5
+ #
6
+ # Using a class method to limit the bindings referenced by the hash's
7
+ # default_proc
8
+
9
+ def self.hash_of_arrays # :nodoc:
10
+ Hash.new { |h,k| h[k] = [] }
11
+ end
12
+
13
+ def initialize(size = 0, &block)
14
+ super
15
+
16
+ @enqueued = 0
17
+ @ques = self.class.hash_of_arrays
18
+ @lru = {}
19
+ @key = :"connection_args-#{object_id}"
20
+ end
21
+
22
+ def empty?
23
+ (@created - @enqueued) >= @max
24
+ end
25
+
26
+ def length
27
+ @max - @created + @enqueued
28
+ end
29
+
30
+ private
31
+
32
+ def connection_stored? options = {} # :nodoc:
33
+ !@ques[options[:connection_args]].empty?
34
+ end
35
+
36
+ def fetch_connection options = {} # :nodoc:
37
+ connection_args = options[:connection_args]
38
+
39
+ @enqueued -= 1
40
+ lru_update connection_args
41
+ @ques[connection_args].pop
42
+ end
43
+
44
+ def lru_update connection_args # :nodoc:
45
+ @lru.delete connection_args
46
+ @lru[connection_args] = true
47
+ end
48
+
49
+ def shutdown_connections # :nodoc:
50
+ @ques.each_key do |key|
51
+ super connection_args: key
52
+ end
53
+ end
54
+
55
+ def store_connection obj, options = {} # :nodoc:
56
+ @ques[options[:connection_args]].push obj
57
+ @enqueued += 1
58
+ end
59
+
60
+ def try_create options = {} # :nodoc:
61
+ connection_args = options[:connection_args]
62
+
63
+ if @created >= @max && @enqueued >= 1
64
+ oldest, = @lru.first
65
+ @lru.delete oldest
66
+ @ques[oldest].pop
67
+
68
+ @created -= 1
69
+ end
70
+
71
+ if @created < @max
72
+ @created += 1
73
+ lru_update connection_args
74
+ return @create_block.call(connection_args)
75
+ end
76
+ end
77
+
78
+ end
79
+