bundler 2.0.2 → 2.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

Files changed (210) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +687 -574
  3. data/LICENSE.md +18 -19
  4. data/README.md +8 -7
  5. data/bundler.gemspec +5 -23
  6. data/exe/bundle +19 -3
  7. data/lib/bundler.rb +121 -68
  8. data/lib/bundler/build_metadata.rb +3 -3
  9. data/lib/bundler/capistrano.rb +5 -5
  10. data/lib/bundler/cli.rb +130 -124
  11. data/lib/bundler/cli/add.rb +27 -16
  12. data/lib/bundler/cli/common.rb +10 -11
  13. data/lib/bundler/cli/config.rb +161 -86
  14. data/lib/bundler/cli/console.rb +2 -2
  15. data/lib/bundler/cli/doctor.rb +4 -4
  16. data/lib/bundler/cli/exec.rb +4 -9
  17. data/lib/bundler/cli/gem.rb +5 -5
  18. data/lib/bundler/cli/info.rb +17 -5
  19. data/lib/bundler/cli/init.rb +1 -1
  20. data/lib/bundler/cli/install.rb +3 -3
  21. data/lib/bundler/cli/issue.rb +1 -1
  22. data/lib/bundler/cli/open.rb +10 -6
  23. data/lib/bundler/cli/outdated.rb +85 -81
  24. data/lib/bundler/cli/package.rb +8 -9
  25. data/lib/bundler/cli/plugin.rb +9 -2
  26. data/lib/bundler/cli/pristine.rb +1 -1
  27. data/lib/bundler/cli/show.rb +1 -1
  28. data/lib/bundler/cli/update.rb +32 -12
  29. data/lib/bundler/compact_index_client.rb +25 -9
  30. data/lib/bundler/compact_index_client/updater.rb +2 -6
  31. data/lib/bundler/current_ruby.rb +8 -7
  32. data/lib/bundler/definition.rb +33 -26
  33. data/lib/bundler/dependency.rb +16 -4
  34. data/lib/bundler/deployment.rb +2 -2
  35. data/lib/bundler/dsl.rb +18 -42
  36. data/lib/bundler/env.rb +6 -5
  37. data/lib/bundler/environment_preserver.rb +0 -1
  38. data/lib/bundler/feature_flag.rb +0 -12
  39. data/lib/bundler/fetcher.rb +14 -11
  40. data/lib/bundler/fetcher/compact_index.rb +26 -12
  41. data/lib/bundler/fetcher/dependency.rb +1 -1
  42. data/lib/bundler/fetcher/downloader.rb +3 -0
  43. data/lib/bundler/fetcher/index.rb +4 -2
  44. data/lib/bundler/friendly_errors.rb +4 -5
  45. data/lib/bundler/gem_helper.rb +8 -8
  46. data/lib/bundler/gem_helpers.rb +2 -4
  47. data/lib/bundler/gem_tasks.rb +1 -1
  48. data/lib/bundler/gem_version_promoter.rb +3 -3
  49. data/lib/bundler/graph.rb +2 -2
  50. data/lib/bundler/injector.rb +3 -1
  51. data/lib/bundler/inline.rb +19 -18
  52. data/lib/bundler/installer.rb +7 -14
  53. data/lib/bundler/installer/gem_installer.rb +5 -1
  54. data/lib/bundler/installer/parallel_installer.rb +4 -4
  55. data/lib/bundler/installer/standalone.rb +1 -2
  56. data/lib/bundler/lazy_specification.rb +2 -2
  57. data/lib/bundler/lockfile_parser.rb +13 -21
  58. data/lib/bundler/match_platform.rb +1 -1
  59. data/lib/bundler/plugin.rb +29 -18
  60. data/lib/bundler/plugin/api.rb +1 -1
  61. data/lib/bundler/plugin/api/source.rb +2 -2
  62. data/lib/bundler/plugin/index.rb +10 -2
  63. data/lib/bundler/plugin/installer.rb +28 -15
  64. data/lib/bundler/psyched_yaml.rb +1 -1
  65. data/lib/bundler/resolver.rb +72 -24
  66. data/lib/bundler/resolver/spec_group.rb +2 -2
  67. data/lib/bundler/retry.rb +2 -2
  68. data/lib/bundler/ruby_version.rb +4 -19
  69. data/lib/bundler/rubygems_ext.rb +10 -65
  70. data/lib/bundler/rubygems_gem_installer.rb +1 -1
  71. data/lib/bundler/rubygems_integration.rb +135 -403
  72. data/lib/bundler/runtime.rb +2 -9
  73. data/lib/bundler/settings.rb +15 -48
  74. data/lib/bundler/setup.rb +6 -5
  75. data/lib/bundler/shared_helpers.rb +53 -68
  76. data/lib/bundler/similarity_detector.rb +2 -2
  77. data/lib/bundler/source.rb +5 -5
  78. data/lib/bundler/source/git.rb +19 -12
  79. data/lib/bundler/source/git/git_proxy.rb +35 -39
  80. data/lib/bundler/source/metadata.rb +7 -2
  81. data/lib/bundler/source/path.rb +13 -8
  82. data/lib/bundler/source/rubygems.rb +11 -5
  83. data/lib/bundler/source/rubygems/remote.rb +1 -2
  84. data/lib/bundler/source_list.rb +9 -12
  85. data/lib/bundler/spec_set.rb +1 -6
  86. data/lib/bundler/stub_specification.rb +18 -30
  87. data/lib/bundler/templates/Executable.bundler +22 -13
  88. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +3 -3
  89. data/lib/bundler/templates/newgem/Gemfile.tt +8 -0
  90. data/lib/bundler/templates/newgem/README.md.tt +4 -3
  91. data/lib/bundler/templates/newgem/newgem.gemspec.tt +2 -18
  92. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +0 -4
  93. data/lib/bundler/templates/newgem/travis.yml.tt +0 -1
  94. data/lib/bundler/ui.rb +3 -3
  95. data/lib/bundler/ui/rg_proxy.rb +1 -1
  96. data/lib/bundler/ui/shell.rb +4 -8
  97. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +161 -0
  98. data/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +66 -0
  99. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +176 -0
  100. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +3 -0
  101. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1 -1
  102. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +6 -6
  103. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  104. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +1 -1
  105. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +1 -1
  106. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +1 -1
  107. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +1 -1
  108. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +6 -6
  109. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +1 -1
  110. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +1 -1
  111. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +30 -8
  112. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +1 -1
  113. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +4 -4
  114. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +2 -2
  115. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +248 -279
  116. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +40 -0
  117. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +53 -0
  118. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +79 -0
  119. data/lib/bundler/vendor/thor/lib/thor.rb +1 -1
  120. data/lib/bundler/vendor/thor/lib/thor/actions.rb +7 -7
  121. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +1 -1
  122. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +1 -1
  123. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +1 -1
  124. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +1 -1
  125. data/lib/bundler/vendor/thor/lib/thor/base.rb +13 -13
  126. data/lib/bundler/vendor/thor/lib/thor/group.rb +1 -1
  127. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +2 -2
  128. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -4
  129. data/lib/bundler/vendor/thor/lib/thor/runner.rb +4 -4
  130. data/lib/bundler/vendor/thor/lib/thor/shell.rb +3 -3
  131. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +1 -1
  132. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +1 -1
  133. data/lib/bundler/vendor/thor/lib/thor/util.rb +1 -1
  134. data/lib/bundler/vendored_fileutils.rb +1 -6
  135. data/lib/bundler/vendored_molinillo.rb +1 -1
  136. data/lib/bundler/vendored_persistent.rb +7 -5
  137. data/lib/bundler/vendored_thor.rb +2 -2
  138. data/lib/bundler/version.rb +1 -20
  139. data/lib/bundler/version_ranges.rb +51 -5
  140. data/lib/bundler/vlad.rb +3 -3
  141. data/lib/bundler/worker.rb +1 -3
  142. data/lib/bundler/yaml_serializer.rb +2 -3
  143. data/man/bundle-add.1 +10 -2
  144. data/man/bundle-add.1.txt +11 -5
  145. data/man/bundle-add.ronn +7 -1
  146. data/man/bundle-binstubs.1 +2 -2
  147. data/man/bundle-binstubs.1.txt +2 -2
  148. data/man/bundle-binstubs.ronn +1 -1
  149. data/man/bundle-check.1 +1 -1
  150. data/man/bundle-check.1.txt +6 -6
  151. data/man/bundle-clean.1 +1 -1
  152. data/man/bundle-clean.1.txt +1 -1
  153. data/man/bundle-config.1 +35 -35
  154. data/man/bundle-config.1.txt +65 -66
  155. data/man/bundle-config.ronn +41 -39
  156. data/man/bundle-doctor.1 +1 -1
  157. data/man/bundle-doctor.1.txt +1 -1
  158. data/man/bundle-exec.1 +1 -1
  159. data/man/bundle-exec.1.txt +1 -1
  160. data/man/bundle-gem.1 +1 -1
  161. data/man/bundle-gem.1.txt +3 -3
  162. data/man/bundle-info.1 +1 -1
  163. data/man/bundle-info.1.txt +1 -1
  164. data/man/bundle-init.1 +1 -1
  165. data/man/bundle-init.1.txt +1 -1
  166. data/man/bundle-inject.1 +1 -1
  167. data/man/bundle-inject.1.txt +1 -1
  168. data/man/bundle-install.1 +8 -5
  169. data/man/bundle-install.1.txt +56 -51
  170. data/man/bundle-install.ronn +9 -4
  171. data/man/bundle-list.1 +1 -1
  172. data/man/bundle-list.1.txt +1 -1
  173. data/man/bundle-lock.1 +1 -1
  174. data/man/bundle-lock.1.txt +16 -16
  175. data/man/bundle-open.1 +1 -1
  176. data/man/bundle-open.1.txt +1 -1
  177. data/man/bundle-outdated.1 +1 -1
  178. data/man/bundle-outdated.1.txt +1 -1
  179. data/man/bundle-package.1 +1 -1
  180. data/man/bundle-package.1.txt +1 -1
  181. data/man/bundle-platform.1 +1 -1
  182. data/man/bundle-platform.1.txt +1 -1
  183. data/man/bundle-pristine.1 +1 -1
  184. data/man/bundle-pristine.1.txt +1 -1
  185. data/man/bundle-remove.1 +1 -1
  186. data/man/bundle-remove.1.txt +1 -1
  187. data/man/bundle-show.1 +1 -1
  188. data/man/bundle-show.1.txt +1 -1
  189. data/man/bundle-update.1 +4 -4
  190. data/man/bundle-update.1.txt +64 -65
  191. data/man/bundle-update.ronn +3 -3
  192. data/man/bundle-viz.1 +1 -1
  193. data/man/bundle-viz.1.txt +1 -1
  194. data/man/bundle.1 +2 -2
  195. data/man/bundle.1.txt +7 -7
  196. data/man/bundle.ronn +1 -1
  197. data/man/gemfile.5 +12 -15
  198. data/man/gemfile.5.ronn +9 -13
  199. data/man/gemfile.5.txt +103 -107
  200. metadata +11 -112
  201. data/exe/bundle_ruby +0 -60
  202. data/lib/bundler/cli/cache.rb +0 -36
  203. data/lib/bundler/compatibility_guard.rb +0 -13
  204. data/lib/bundler/ssl_certs/.document +0 -1
  205. data/lib/bundler/ssl_certs/certificate_manager.rb +0 -66
  206. data/lib/bundler/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +0 -21
  207. data/lib/bundler/ssl_certs/rubygems.global.ssl.fastly.net/DigiCertHighAssuranceEVRootCA.pem +0 -23
  208. data/lib/bundler/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem +0 -25
  209. data/lib/bundler/vendor/net-http-persistent/lib/net/http/faster.rb +0 -27
  210. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse.rb +0 -129
@@ -0,0 +1,176 @@
1
+ require 'thread'
2
+ require 'timeout'
3
+ require_relative 'monotonic_time'
4
+
5
+ ##
6
+ # Raised when you attempt to retrieve a connection from a pool that has been
7
+ # shut down.
8
+
9
+ class Bundler::ConnectionPool::PoolShuttingDownError < RuntimeError; end
10
+
11
+ ##
12
+ # The TimedStack manages a pool of homogeneous connections (or any resource
13
+ # you wish to manage). Connections are created lazily up to a given maximum
14
+ # number.
15
+
16
+ # Examples:
17
+ #
18
+ # ts = TimedStack.new(1) { MyConnection.new }
19
+ #
20
+ # # fetch a connection
21
+ # conn = ts.pop
22
+ #
23
+ # # return a connection
24
+ # ts.push conn
25
+ #
26
+ # conn = ts.pop
27
+ # ts.pop timeout: 5
28
+ # #=> raises Timeout::Error after 5 seconds
29
+
30
+ class Bundler::ConnectionPool::TimedStack
31
+ attr_reader :max
32
+
33
+ ##
34
+ # Creates a new pool with +size+ connections that are created from the given
35
+ # +block+.
36
+
37
+ def initialize(size = 0, &block)
38
+ @create_block = block
39
+ @created = 0
40
+ @que = []
41
+ @max = size
42
+ @mutex = Mutex.new
43
+ @resource = ConditionVariable.new
44
+ @shutdown_block = nil
45
+ end
46
+
47
+ ##
48
+ # Returns +obj+ to the stack. +options+ is ignored in TimedStack but may be
49
+ # used by subclasses that extend TimedStack.
50
+
51
+ def push(obj, options = {})
52
+ @mutex.synchronize do
53
+ if @shutdown_block
54
+ @shutdown_block.call(obj)
55
+ else
56
+ store_connection obj, options
57
+ end
58
+
59
+ @resource.broadcast
60
+ end
61
+ end
62
+ alias_method :<<, :push
63
+
64
+ ##
65
+ # Retrieves a connection from the stack. If a connection is available it is
66
+ # immediately returned. If no connection is available within the given
67
+ # timeout a Timeout::Error is raised.
68
+ #
69
+ # +:timeout+ is the only checked entry in +options+ and is preferred over
70
+ # the +timeout+ argument (which will be removed in a future release). Other
71
+ # options may be used by subclasses that extend TimedStack.
72
+
73
+ def pop(timeout = 0.5, options = {})
74
+ options, timeout = timeout, 0.5 if Hash === timeout
75
+ timeout = options.fetch :timeout, timeout
76
+
77
+ deadline = Bundler::ConnectionPool.monotonic_time + timeout
78
+ @mutex.synchronize do
79
+ loop do
80
+ raise Bundler::ConnectionPool::PoolShuttingDownError if @shutdown_block
81
+ return fetch_connection(options) if connection_stored?(options)
82
+
83
+ connection = try_create(options)
84
+ return connection if connection
85
+
86
+ to_wait = deadline - Bundler::ConnectionPool.monotonic_time
87
+ raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0
88
+ @resource.wait(@mutex, to_wait)
89
+ end
90
+ end
91
+ end
92
+
93
+ ##
94
+ # Shuts down the TimedStack which prevents connections from being checked
95
+ # out. The +block+ is called once for each connection on the stack.
96
+
97
+ def shutdown(&block)
98
+ raise ArgumentError, "shutdown must receive a block" unless block_given?
99
+
100
+ @mutex.synchronize do
101
+ @shutdown_block = block
102
+ @resource.broadcast
103
+
104
+ shutdown_connections
105
+ end
106
+ end
107
+
108
+ ##
109
+ # Returns +true+ if there are no available connections.
110
+
111
+ def empty?
112
+ (@created - @que.length) >= @max
113
+ end
114
+
115
+ ##
116
+ # The number of connections available on the stack.
117
+
118
+ def length
119
+ @max - @created + @que.length
120
+ end
121
+
122
+ private
123
+
124
+ ##
125
+ # This is an extension point for TimedStack and is called with a mutex.
126
+ #
127
+ # This method must returns true if a connection is available on the stack.
128
+
129
+ def connection_stored?(options = nil)
130
+ !@que.empty?
131
+ end
132
+
133
+ ##
134
+ # This is an extension point for TimedStack and is called with a mutex.
135
+ #
136
+ # This method must return a connection from the stack.
137
+
138
+ def fetch_connection(options = nil)
139
+ @que.pop
140
+ end
141
+
142
+ ##
143
+ # This is an extension point for TimedStack and is called with a mutex.
144
+ #
145
+ # This method must shut down all connections on the stack.
146
+
147
+ def shutdown_connections(options = nil)
148
+ while connection_stored?(options)
149
+ conn = fetch_connection(options)
150
+ @shutdown_block.call(conn)
151
+ end
152
+ end
153
+
154
+ ##
155
+ # This is an extension point for TimedStack and is called with a mutex.
156
+ #
157
+ # This method must return +obj+ to the stack.
158
+
159
+ def store_connection(obj, options = nil)
160
+ @que.push obj
161
+ end
162
+
163
+ ##
164
+ # This is an extension point for TimedStack and is called with a mutex.
165
+ #
166
+ # This method must create a connection if and only if the total number of
167
+ # connections allowed has not been met.
168
+
169
+ def try_create(options = nil)
170
+ unless @created == @max
171
+ object = @create_block.call
172
+ @created += 1
173
+ object
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,3 @@
1
+ class Bundler::ConnectionPool
2
+ VERSION = "2.2.2"
3
+ end
@@ -6,7 +6,7 @@ rescue LoadError
6
6
  # for make mjit-headers
7
7
  end
8
8
 
9
- require "bundler/vendor/fileutils/lib/fileutils/version"
9
+ require_relative "fileutils/version"
10
10
 
11
11
  #
12
12
  # = fileutils.rb
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/compatibility'
4
- require 'bundler/vendor/molinillo/lib/molinillo/gem_metadata'
5
- require 'bundler/vendor/molinillo/lib/molinillo/errors'
6
- require 'bundler/vendor/molinillo/lib/molinillo/resolver'
7
- require 'bundler/vendor/molinillo/lib/molinillo/modules/ui'
8
- require 'bundler/vendor/molinillo/lib/molinillo/modules/specification_provider'
3
+ require_relative 'molinillo/compatibility'
4
+ require_relative 'molinillo/gem_metadata'
5
+ require_relative 'molinillo/errors'
6
+ require_relative 'molinillo/resolver'
7
+ require_relative 'molinillo/modules/ui'
8
+ require_relative 'molinillo/modules/specification_provider'
9
9
 
10
10
  # Bundler::Molinillo is a generic dependency resolution algorithm.
11
11
  module Bundler::Molinillo
@@ -3,8 +3,8 @@
3
3
  require 'set'
4
4
  require 'tsort'
5
5
 
6
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/log'
7
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex'
6
+ require_relative 'dependency_graph/log'
7
+ require_relative 'dependency_graph/vertex'
8
8
 
9
9
  module Bundler::Molinillo
10
10
  # A directed acyclic graph that is tuned to hold named dependencies
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action'
3
+ require_relative 'action'
4
4
  module Bundler::Molinillo
5
5
  class DependencyGraph
6
6
  # @!visibility private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action'
3
+ require_relative 'action'
4
4
  module Bundler::Molinillo
5
5
  class DependencyGraph
6
6
  # @!visibility private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action'
3
+ require_relative 'action'
4
4
  module Bundler::Molinillo
5
5
  class DependencyGraph
6
6
  # @!visibility private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action'
3
+ require_relative 'action'
4
4
  module Bundler::Molinillo
5
5
  class DependencyGraph
6
6
  # @!visibility private
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular'
4
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex'
5
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge'
6
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named'
7
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload'
8
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag'
3
+ require_relative 'add_edge_no_circular'
4
+ require_relative 'add_vertex'
5
+ require_relative 'delete_edge'
6
+ require_relative 'detach_vertex_named'
7
+ require_relative 'set_payload'
8
+ require_relative 'tag'
9
9
 
10
10
  module Bundler::Molinillo
11
11
  class DependencyGraph
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action'
3
+ require_relative 'action'
4
4
  module Bundler::Molinillo
5
5
  class DependencyGraph
6
6
  # @!visibility private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph/action'
3
+ require_relative 'action'
4
4
  module Bundler::Molinillo
5
5
  class DependencyGraph
6
6
  # @!visibility private
@@ -50,14 +50,25 @@ module Bundler::Molinillo
50
50
  incoming_edges.map(&:origin)
51
51
  end
52
52
 
53
- # @return [Array<Vertex>] the vertices of {#graph} where `self` is a
53
+ # @return [Set<Vertex>] the vertices of {#graph} where `self` is a
54
54
  # {#descendent?}
55
55
  def recursive_predecessors
56
- vertices = predecessors
57
- vertices += Compatibility.flat_map(vertices, &:recursive_predecessors)
58
- vertices.uniq!
56
+ _recursive_predecessors
57
+ end
58
+
59
+ # @param [Set<Vertex>] vertices the set to add the predecessors to
60
+ # @return [Set<Vertex>] the vertices of {#graph} where `self` is a
61
+ # {#descendent?}
62
+ def _recursive_predecessors(vertices = Set.new)
63
+ incoming_edges.each do |edge|
64
+ vertex = edge.origin
65
+ next unless vertices.add?(vertex)
66
+ vertex._recursive_predecessors(vertices)
67
+ end
68
+
59
69
  vertices
60
70
  end
71
+ protected :_recursive_predecessors
61
72
 
62
73
  # @return [Array<Vertex>] the vertices of {#graph} that have an edge with
63
74
  # `self` as their {Edge#origin}
@@ -65,14 +76,25 @@ module Bundler::Molinillo
65
76
  outgoing_edges.map(&:destination)
66
77
  end
67
78
 
68
- # @return [Array<Vertex>] the vertices of {#graph} where `self` is an
79
+ # @return [Set<Vertex>] the vertices of {#graph} where `self` is an
69
80
  # {#ancestor?}
70
81
  def recursive_successors
71
- vertices = successors
72
- vertices += Compatibility.flat_map(vertices, &:recursive_successors)
73
- vertices.uniq!
82
+ _recursive_successors
83
+ end
84
+
85
+ # @param [Set<Vertex>] vertices the set to add the successors to
86
+ # @return [Set<Vertex>] the vertices of {#graph} where `self` is an
87
+ # {#ancestor?}
88
+ def _recursive_successors(vertices = Set.new)
89
+ outgoing_edges.each do |edge|
90
+ vertex = edge.destination
91
+ next unless vertices.add?(vertex)
92
+ vertex._recursive_successors(vertices)
93
+ end
94
+
74
95
  vertices
75
96
  end
97
+ protected :_recursive_successors
76
98
 
77
99
  # @return [String] a string suitable for debugging
78
100
  def inspect
@@ -80,7 +80,7 @@ module Bundler::Molinillo
80
80
  @specification_provider = specification_provider
81
81
  end
82
82
 
83
- require 'bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider'
83
+ require_relative 'delegates/specification_provider'
84
84
  include Delegates::SpecificationProvider
85
85
 
86
86
  # @return [String] An error message that includes requirement trees,
@@ -238,11 +238,11 @@ module Bundler::Molinillo
238
238
  debug { 'Activated: ' + Hash[activated.vertices.select { |_n, v| v.payload }].keys.join(', ') } if state
239
239
  end
240
240
 
241
- require 'bundler/vendor/molinillo/lib/molinillo/state'
242
- require 'bundler/vendor/molinillo/lib/molinillo/modules/specification_provider'
241
+ require_relative 'state'
242
+ require_relative 'modules/specification_provider'
243
243
 
244
- require 'bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state'
245
- require 'bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider'
244
+ require_relative 'delegates/resolution_state'
245
+ require_relative 'delegates/specification_provider'
246
246
 
247
247
  include Bundler::Molinillo::Delegates::ResolutionState
248
248
  include Bundler::Molinillo::Delegates::SpecificationProvider
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/vendor/molinillo/lib/molinillo/dependency_graph'
3
+ require_relative 'dependency_graph'
4
4
 
5
5
  module Bundler::Molinillo
6
6
  # This class encapsulates a dependency resolver.
@@ -9,7 +9,7 @@ module Bundler::Molinillo
9
9
  #
10
10
  #
11
11
  class Resolver
12
- require 'bundler/vendor/molinillo/lib/molinillo/resolution'
12
+ require_relative 'resolution'
13
13
 
14
14
  # @return [SpecificationProvider] the specification provider used
15
15
  # in the resolution process
@@ -1,12 +1,7 @@
1
1
  require 'net/http'
2
- begin
3
- require 'net/https'
4
- rescue LoadError
5
- # net/https or openssl
6
- end if RUBY_VERSION < '1.9' # but only for 1.8
7
- require 'bundler/vendor/net-http-persistent/lib/net/http/faster'
8
2
  require 'uri'
9
3
  require 'cgi' # for escaping
4
+ require_relative '../../../../connection_pool/lib/connection_pool'
10
5
 
11
6
  begin
12
7
  require 'net/http/pipeline'
@@ -38,7 +33,7 @@ autoload :OpenSSL, 'openssl'
38
33
  #
39
34
  # uri = URI 'http://example.com/awesome/web/service'
40
35
  #
41
- # http = Bundler::Persistent::Net::HTTP::Persistent.new 'my_app_name'
36
+ # http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name'
42
37
  #
43
38
  # # perform a GET
44
39
  # response = http.request uri
@@ -70,13 +65,17 @@ autoload :OpenSSL, 'openssl'
70
65
  # Here are the SSL settings, see the individual methods for documentation:
71
66
  #
72
67
  # #certificate :: This client's certificate
73
- # #ca_file :: The certificate-authority
68
+ # #ca_file :: The certificate-authorities
69
+ # #ca_path :: Directory with certificate-authorities
74
70
  # #cert_store :: An SSL certificate store
71
+ # #ciphers :: List of SSl ciphers allowed
75
72
  # #private_key :: The client's SSL private key
76
73
  # #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new
77
74
  # connection
75
+ # #ssl_timeout :: SSL session lifetime
78
76
  # #ssl_version :: Which specific SSL version to use
79
77
  # #verify_callback :: For server certificate verification
78
+ # #verify_depth :: Depth of certificate verification
80
79
  # #verify_mode :: How connections should be verified
81
80
  #
82
81
  # == Proxies
@@ -154,7 +153,7 @@ autoload :OpenSSL, 'openssl'
154
153
  # uri = URI 'http://example.com/awesome/web/service'
155
154
  # post_uri = uri + 'create'
156
155
  #
157
- # http = Bundler::Persistent::Net::HTTP::Persistent.new 'my_app_name'
156
+ # http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name'
158
157
  #
159
158
  # post = Net::HTTP::Post.new post_uri.path
160
159
  # # ... fill in POST request
@@ -200,10 +199,19 @@ class Bundler::Persistent::Net::HTTP::Persistent
200
199
 
201
200
  HAVE_OPENSSL = defined? OpenSSL::SSL # :nodoc:
202
201
 
202
+ ##
203
+ # The default connection pool size is 1/4 the allowed open files.
204
+
205
+ if Gem.win_platform? then
206
+ DEFAULT_POOL_SIZE = 256
207
+ else
208
+ DEFAULT_POOL_SIZE = Process.getrlimit(Process::RLIMIT_NOFILE).first / 4
209
+ end
210
+
203
211
  ##
204
212
  # The version of Bundler::Persistent::Net::HTTP::Persistent you are using
205
213
 
206
- VERSION = '2.9.4'
214
+ VERSION = '3.1.0'
207
215
 
208
216
  ##
209
217
  # Exceptions rescued for automatic retry on ruby 2.0.0. This overlaps with
@@ -248,31 +256,31 @@ class Bundler::Persistent::Net::HTTP::Persistent
248
256
 
249
257
  http = new 'net-http-persistent detect_idle_timeout'
250
258
 
251
- connection = http.connection_for uri
259
+ http.connection_for uri do |connection|
260
+ sleep_time = 0
252
261
 
253
- sleep_time = 0
262
+ http = connection.http
254
263
 
255
- loop do
256
- response = connection.request req
264
+ loop do
265
+ response = http.request req
257
266
 
258
- $stderr.puts "HEAD #{uri} => #{response.code}" if $DEBUG
267
+ $stderr.puts "HEAD #{uri} => #{response.code}" if $DEBUG
259
268
 
260
- unless Net::HTTPOK === response then
261
- raise Error, "bad response code #{response.code} detecting idle timeout"
262
- end
269
+ unless Net::HTTPOK === response then
270
+ raise Error, "bad response code #{response.code} detecting idle timeout"
271
+ end
263
272
 
264
- break if sleep_time >= max
273
+ break if sleep_time >= max
265
274
 
266
- sleep_time += 1
275
+ sleep_time += 1
267
276
 
268
- $stderr.puts "sleeping #{sleep_time}" if $DEBUG
269
- sleep sleep_time
277
+ $stderr.puts "sleeping #{sleep_time}" if $DEBUG
278
+ sleep sleep_time
279
+ end
270
280
  end
271
281
  rescue
272
282
  # ignore StandardErrors, we've probably found the idle timeout.
273
283
  ensure
274
- http.shutdown
275
-
276
284
  return sleep_time unless $!
277
285
  end
278
286
 
@@ -281,7 +289,9 @@ class Bundler::Persistent::Net::HTTP::Persistent
281
289
 
282
290
  attr_reader :certificate
283
291
 
292
+ ##
284
293
  # For Net::HTTP parity
294
+
285
295
  alias cert certificate
286
296
 
287
297
  ##
@@ -290,12 +300,23 @@ class Bundler::Persistent::Net::HTTP::Persistent
290
300
 
291
301
  attr_reader :ca_file
292
302
 
303
+ ##
304
+ # A directory of SSL certificates to be used as certificate authorities.
305
+ # Setting this will set verify_mode to VERIFY_PEER.
306
+
307
+ attr_reader :ca_path
308
+
293
309
  ##
294
310
  # An SSL certificate store. Setting this will override the default
295
311
  # certificate store. See verify_mode for more information.
296
312
 
297
313
  attr_reader :cert_store
298
314
 
315
+ ##
316
+ # The ciphers allowed for SSL connections
317
+
318
+ attr_reader :ciphers
319
+
299
320
  ##
300
321
  # Sends debug_output to this IO via Net::HTTP#set_debug_output.
301
322
  #
@@ -309,11 +330,6 @@ class Bundler::Persistent::Net::HTTP::Persistent
309
330
 
310
331
  attr_reader :generation # :nodoc:
311
332
 
312
- ##
313
- # Where this instance's connections live in the thread local variables
314
-
315
- attr_reader :generation_key # :nodoc:
316
-
317
333
  ##
318
334
  # Headers that are added to every request using Net::HTTP#add_field
319
335
 
@@ -369,7 +385,9 @@ class Bundler::Persistent::Net::HTTP::Persistent
369
385
 
370
386
  attr_reader :private_key
371
387
 
388
+ ##
372
389
  # For Net::HTTP parity
390
+
373
391
  alias key private_key
374
392
 
375
393
  ##
@@ -382,15 +400,20 @@ class Bundler::Persistent::Net::HTTP::Persistent
382
400
 
383
401
  attr_reader :no_proxy
384
402
 
403
+ ##
404
+ # Test-only accessor for the connection pool
405
+
406
+ attr_reader :pool # :nodoc:
407
+
385
408
  ##
386
409
  # Seconds to wait until reading one block. See Net::HTTP#read_timeout
387
410
 
388
411
  attr_accessor :read_timeout
389
412
 
390
413
  ##
391
- # Where this instance's request counts live in the thread local variables
414
+ # Seconds to wait until writing one block. See Net::HTTP#write_timeout
392
415
 
393
- attr_reader :request_key # :nodoc:
416
+ attr_accessor :write_timeout
394
417
 
395
418
  ##
396
419
  # By default SSL sessions are reused to avoid extra SSL handshakes. Set
@@ -418,17 +441,33 @@ class Bundler::Persistent::Net::HTTP::Persistent
418
441
  attr_reader :ssl_generation # :nodoc:
419
442
 
420
443
  ##
421
- # Where this instance's SSL connections live in the thread local variables
444
+ # SSL session lifetime
422
445
 
423
- attr_reader :ssl_generation_key # :nodoc:
446
+ attr_reader :ssl_timeout
424
447
 
425
448
  ##
426
449
  # SSL version to use.
427
450
  #
428
451
  # By default, the version will be negotiated automatically between client
429
- # and server. Ruby 1.9 and newer only.
452
+ # and server. Ruby 1.9 and newer only. Deprecated since Ruby 2.5.
430
453
 
431
- attr_reader :ssl_version if RUBY_VERSION > '1.9'
454
+ attr_reader :ssl_version
455
+
456
+ ##
457
+ # Minimum SSL version to use, e.g. :TLS1_1
458
+ #
459
+ # By default, the version will be negotiated automatically between client
460
+ # and server. Ruby 2.5 and newer only.
461
+
462
+ attr_reader :min_version
463
+
464
+ ##
465
+ # Maximum SSL version to use, e.g. :TLS1_2
466
+ #
467
+ # By default, the version will be negotiated automatically between client
468
+ # and server. Ruby 2.5 and newer only.
469
+
470
+ attr_reader :max_version
432
471
 
433
472
  ##
434
473
  # Where this instance's last-use times live in the thread local variables
@@ -436,16 +475,21 @@ class Bundler::Persistent::Net::HTTP::Persistent
436
475
  attr_reader :timeout_key # :nodoc:
437
476
 
438
477
  ##
439
- # SSL verification callback. Used when ca_file is set.
478
+ # SSL verification callback. Used when ca_file or ca_path is set.
440
479
 
441
480
  attr_reader :verify_callback
442
481
 
482
+ ##
483
+ # Sets the depth of SSL certificate verification
484
+
485
+ attr_reader :verify_depth
486
+
443
487
  ##
444
488
  # HTTPS verify mode. Defaults to OpenSSL::SSL::VERIFY_PEER which verifies
445
489
  # the server certificate.
446
490
  #
447
- # If no ca_file or cert_store is set the default system certificate store is
448
- # used.
491
+ # If no ca_file, ca_path or cert_store is set the default system certificate
492
+ # store is used.
449
493
  #
450
494
  # You can use +verify_mode+ to override any default values.
451
495
 
@@ -478,8 +522,12 @@ class Bundler::Persistent::Net::HTTP::Persistent
478
522
  # proxy = URI 'http://proxy.example'
479
523
  # proxy.user = 'AzureDiamond'
480
524
  # proxy.password = 'hunter2'
525
+ #
526
+ # Set +pool_size+ to limit the maximum number of connections allowed.
527
+ # Defaults to 1/4 the number of allowed file handles. You can have no more
528
+ # than this many threads with active HTTP transactions.
481
529
 
482
- def initialize name = nil, proxy = nil
530
+ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
483
531
  @name = name
484
532
 
485
533
  @debug_output = nil
@@ -491,29 +539,34 @@ class Bundler::Persistent::Net::HTTP::Persistent
491
539
  @keep_alive = 30
492
540
  @open_timeout = nil
493
541
  @read_timeout = nil
542
+ @write_timeout = nil
494
543
  @idle_timeout = 5
495
544
  @max_requests = nil
496
545
  @socket_options = []
546
+ @ssl_generation = 0 # incremented when SSL session variables change
497
547
 
498
548
  @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
499
549
  Socket.const_defined? :TCP_NODELAY
500
550
 
501
- key = ['net_http_persistent', name].compact
502
- @generation_key = [key, 'generations' ].join('_').intern
503
- @ssl_generation_key = [key, 'ssl_generations'].join('_').intern
504
- @request_key = [key, 'requests' ].join('_').intern
505
- @timeout_key = [key, 'timeouts' ].join('_').intern
551
+ @pool = Bundler::Persistent::Net::HTTP::Persistent::Pool.new size: pool_size do |http_args|
552
+ Bundler::Persistent::Net::HTTP::Persistent::Connection.new Net::HTTP, http_args, @ssl_generation
553
+ end
506
554
 
507
555
  @certificate = nil
508
556
  @ca_file = nil
557
+ @ca_path = nil
558
+ @ciphers = nil
509
559
  @private_key = nil
560
+ @ssl_timeout = nil
510
561
  @ssl_version = nil
562
+ @min_version = nil
563
+ @max_version = nil
511
564
  @verify_callback = nil
565
+ @verify_depth = nil
512
566
  @verify_mode = nil
513
567
  @cert_store = nil
514
568
 
515
569
  @generation = 0 # incremented when proxy URI changes
516
- @ssl_generation = 0 # incremented when SSL session variables change
517
570
 
518
571
  if HAVE_OPENSSL then
519
572
  @verify_mode = OpenSSL::SSL::VERIFY_PEER
@@ -522,9 +575,6 @@ class Bundler::Persistent::Net::HTTP::Persistent
522
575
 
523
576
  @retry_change_requests = false
524
577
 
525
- @ruby_1 = RUBY_VERSION < '2'
526
- @retried_on_ruby_2 = !@ruby_1
527
-
528
578
  self.proxy = proxy if proxy
529
579
  end
530
580
 
@@ -549,6 +599,15 @@ class Bundler::Persistent::Net::HTTP::Persistent
549
599
  reconnect_ssl
550
600
  end
551
601
 
602
+ ##
603
+ # Sets the SSL certificate authority path.
604
+
605
+ def ca_path= path
606
+ @ca_path = path
607
+
608
+ reconnect_ssl
609
+ end
610
+
552
611
  ##
553
612
  # Overrides the default SSL certificate store used for verifying
554
613
  # connections.
@@ -560,92 +619,59 @@ class Bundler::Persistent::Net::HTTP::Persistent
560
619
  end
561
620
 
562
621
  ##
563
- # Finishes all connections on the given +thread+ that were created before
564
- # the given +generation+ in the threads +generation_key+ list.
565
- #
566
- # See #shutdown for a bunch of scary warning about misusing this method.
567
-
568
- def cleanup(generation, thread = Thread.current,
569
- generation_key = @generation_key) # :nodoc:
570
- timeouts = thread[@timeout_key]
571
-
572
- (0...generation).each do |old_generation|
573
- next unless thread[generation_key]
574
-
575
- conns = thread[generation_key].delete old_generation
622
+ # The ciphers allowed for SSL connections
576
623
 
577
- conns.each_value do |conn|
578
- finish conn, thread
624
+ def ciphers= ciphers
625
+ @ciphers = ciphers
579
626
 
580
- timeouts.delete conn.object_id if timeouts
581
- end if conns
582
- end
627
+ reconnect_ssl
583
628
  end
584
629
 
585
630
  ##
586
631
  # Creates a new connection for +uri+
587
632
 
588
633
  def connection_for uri
589
- Thread.current[@generation_key] ||= Hash.new { |h,k| h[k] = {} }
590
- Thread.current[@ssl_generation_key] ||= Hash.new { |h,k| h[k] = {} }
591
- Thread.current[@request_key] ||= Hash.new 0
592
- Thread.current[@timeout_key] ||= Hash.new EPOCH
593
-
594
634
  use_ssl = uri.scheme.downcase == 'https'
595
635
 
596
- if use_ssl then
597
- raise Bundler::Persistent::Net::HTTP::Persistent::Error, 'OpenSSL is not available' unless
598
- HAVE_OPENSSL
599
-
600
- ssl_generation = @ssl_generation
601
-
602
- ssl_cleanup ssl_generation
636
+ net_http_args = [uri.hostname, uri.port]
603
637
 
604
- connections = Thread.current[@ssl_generation_key][ssl_generation]
605
- else
606
- generation = @generation
607
-
608
- cleanup generation
609
-
610
- connections = Thread.current[@generation_key][generation]
611
- end
612
-
613
- net_http_args = [uri.host, uri.port]
614
- connection_id = net_http_args.join ':'
615
-
616
- if @proxy_uri and not proxy_bypass? uri.host, uri.port then
617
- connection_id << @proxy_connection_id
638
+ if @proxy_uri and not proxy_bypass? uri.hostname, uri.port then
618
639
  net_http_args.concat @proxy_args
619
640
  else
620
641
  net_http_args.concat [nil, nil, nil, nil]
621
642
  end
622
643
 
623
- connection = connections[connection_id]
644
+ connection = @pool.checkout net_http_args
624
645
 
625
- unless connection = connections[connection_id] then
626
- connections[connection_id] = http_class.new(*net_http_args)
627
- connection = connections[connection_id]
628
- ssl connection if use_ssl
629
- else
630
- reset connection if expired? connection
631
- end
646
+ http = connection.http
632
647
 
633
- start connection unless connection.started?
648
+ connection.ressl @ssl_generation if
649
+ connection.ssl_generation != @ssl_generation
634
650
 
635
- connection.read_timeout = @read_timeout if @read_timeout
636
- connection.keep_alive_timeout = @idle_timeout if @idle_timeout && connection.respond_to?(:keep_alive_timeout=)
651
+ if not http.started? then
652
+ ssl http if use_ssl
653
+ start http
654
+ elsif expired? connection then
655
+ reset connection
656
+ end
637
657
 
638
- connection
658
+ http.read_timeout = @read_timeout if @read_timeout
659
+ http.write_timeout = @write_timeout if @write_timeout && http.respond_to?(:write_timeout=)
660
+ http.keep_alive_timeout = @idle_timeout if @idle_timeout
661
+
662
+ return yield connection
639
663
  rescue Errno::ECONNREFUSED
640
- address = connection.proxy_address || connection.address
641
- port = connection.proxy_port || connection.port
664
+ address = http.proxy_address || http.address
665
+ port = http.proxy_port || http.port
642
666
 
643
667
  raise Error, "connection refused: #{address}:#{port}"
644
668
  rescue Errno::EHOSTDOWN
645
- address = connection.proxy_address || connection.address
646
- port = connection.proxy_port || connection.port
669
+ address = http.proxy_address || http.address
670
+ port = http.proxy_port || http.port
647
671
 
648
672
  raise Error, "host down: #{address}:#{port}"
673
+ ensure
674
+ @pool.checkin net_http_args
649
675
  end
650
676
 
651
677
  ##
@@ -653,12 +679,11 @@ class Bundler::Persistent::Net::HTTP::Persistent
653
679
  # this connection
654
680
 
655
681
  def error_message connection
656
- requests = Thread.current[@request_key][connection.object_id] - 1 # fixup
657
- last_use = Thread.current[@timeout_key][connection.object_id]
682
+ connection.requests -= 1 # fixup
658
683
 
659
- age = Time.now - last_use
684
+ age = Time.now - connection.last_use
660
685
 
661
- "after #{requests} requests on #{connection.object_id}, " \
686
+ "after #{connection.requests} requests on #{connection.http.object_id}, " \
662
687
  "last used #{age} seconds ago"
663
688
  end
664
689
 
@@ -682,26 +707,23 @@ class Bundler::Persistent::Net::HTTP::Persistent
682
707
  # maximum request count, false otherwise.
683
708
 
684
709
  def expired? connection
685
- requests = Thread.current[@request_key][connection.object_id]
686
- return true if @max_requests && requests >= @max_requests
710
+ return true if @max_requests && connection.requests >= @max_requests
687
711
  return false unless @idle_timeout
688
712
  return true if @idle_timeout.zero?
689
713
 
690
- last_used = Thread.current[@timeout_key][connection.object_id]
691
-
692
- Time.now - last_used > @idle_timeout
714
+ Time.now - connection.last_use > @idle_timeout
693
715
  end
694
716
 
695
717
  ##
696
718
  # Starts the Net::HTTP +connection+
697
719
 
698
- def start connection
699
- connection.set_debug_output @debug_output if @debug_output
700
- connection.open_timeout = @open_timeout if @open_timeout
720
+ def start http
721
+ http.set_debug_output @debug_output if @debug_output
722
+ http.open_timeout = @open_timeout if @open_timeout
701
723
 
702
- connection.start
724
+ http.start
703
725
 
704
- socket = connection.instance_variable_get :@socket
726
+ socket = http.instance_variable_get :@socket
705
727
 
706
728
  if socket then # for fakeweb
707
729
  @socket_options.each do |option|
@@ -713,25 +735,11 @@ class Bundler::Persistent::Net::HTTP::Persistent
713
735
  ##
714
736
  # Finishes the Net::HTTP +connection+
715
737
 
716
- def finish connection, thread = Thread.current
717
- if requests = thread[@request_key] then
718
- requests.delete connection.object_id
719
- end
720
-
738
+ def finish connection
721
739
  connection.finish
722
- rescue IOError
723
- end
724
740
 
725
- def http_class # :nodoc:
726
- if RUBY_VERSION > '2.0' then
727
- Net::HTTP
728
- elsif [:Artifice, :FakeWeb, :WebMock].any? { |klass|
729
- Object.const_defined?(klass)
730
- } or not @reuse_ssl_sessions then
731
- Net::HTTP
732
- else
733
- Bundler::Persistent::Net::HTTP::Persistent::SSLReuse
734
- end
741
+ connection.http.instance_variable_set :@ssl_session, nil unless
742
+ @reuse_ssl_sessions
735
743
  end
736
744
 
737
745
  ##
@@ -745,64 +753,17 @@ class Bundler::Persistent::Net::HTTP::Persistent
745
753
  # Is +req+ idempotent according to RFC 2616?
746
754
 
747
755
  def idempotent? req
748
- case req
749
- when Net::HTTP::Delete, Net::HTTP::Get, Net::HTTP::Head,
750
- Net::HTTP::Options, Net::HTTP::Put, Net::HTTP::Trace then
756
+ case req.method
757
+ when 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE' then
751
758
  true
752
759
  end
753
760
  end
754
761
 
755
762
  ##
756
763
  # Is the request +req+ idempotent or is retry_change_requests allowed.
757
- #
758
- # If +retried_on_ruby_2+ is true, true will be returned if we are on ruby,
759
- # retry_change_requests is allowed and the request is not idempotent.
760
764
 
761
- def can_retry? req, retried_on_ruby_2 = false
762
- return @retry_change_requests && !idempotent?(req) if retried_on_ruby_2
763
-
764
- @retry_change_requests || idempotent?(req)
765
- end
766
-
767
- if RUBY_VERSION > '1.9' then
768
- ##
769
- # Workaround for missing Net::HTTPHeader#connection_close? on Ruby 1.8
770
-
771
- def connection_close? header
772
- header.connection_close?
773
- end
774
-
775
- ##
776
- # Workaround for missing Net::HTTPHeader#connection_keep_alive? on Ruby 1.8
777
-
778
- def connection_keep_alive? header
779
- header.connection_keep_alive?
780
- end
781
- else
782
- ##
783
- # Workaround for missing Net::HTTPRequest#connection_close? on Ruby 1.8
784
-
785
- def connection_close? header
786
- header['connection'] =~ /close/ or header['proxy-connection'] =~ /close/
787
- end
788
-
789
- ##
790
- # Workaround for missing Net::HTTPRequest#connection_keep_alive? on Ruby
791
- # 1.8
792
-
793
- def connection_keep_alive? header
794
- header['connection'] =~ /keep-alive/ or
795
- header['proxy-connection'] =~ /keep-alive/
796
- end
797
- end
798
-
799
- ##
800
- # Deprecated in favor of #expired?
801
-
802
- def max_age # :nodoc:
803
- return Time.now + 1 unless @idle_timeout
804
-
805
- Time.now - @idle_timeout
765
+ def can_retry? req
766
+ @retry_change_requests && !idempotent?(req)
806
767
  end
807
768
 
808
769
  ##
@@ -824,9 +785,9 @@ class Bundler::Persistent::Net::HTTP::Persistent
824
785
  # <tt>net-http-persistent</tt> #pipeline will be present.
825
786
 
826
787
  def pipeline uri, requests, &block # :yields: responses
827
- connection = connection_for uri
828
-
829
- connection.pipeline requests, &block
788
+ connection_for uri do |connection|
789
+ connection.http.pipeline requests, &block
790
+ end
830
791
  end
831
792
 
832
793
  ##
@@ -959,18 +920,17 @@ class Bundler::Persistent::Net::HTTP::Persistent
959
920
  # Finishes then restarts the Net::HTTP +connection+
960
921
 
961
922
  def reset connection
962
- Thread.current[@request_key].delete connection.object_id
963
- Thread.current[@timeout_key].delete connection.object_id
923
+ http = connection.http
964
924
 
965
925
  finish connection
966
926
 
967
- start connection
927
+ start http
968
928
  rescue Errno::ECONNREFUSED
969
- e = Error.new "connection refused: #{connection.address}:#{connection.port}"
929
+ e = Error.new "connection refused: #{http.address}:#{http.port}"
970
930
  e.set_backtrace $@
971
931
  raise e
972
932
  rescue Errno::EHOSTDOWN
973
- e = Error.new "host down: #{connection.address}:#{connection.port}"
933
+ e = Error.new "host down: #{http.address}:#{http.port}"
974
934
  e.set_backtrace $@
975
935
  raise e
976
936
  end
@@ -982,7 +942,7 @@ class Bundler::Persistent::Net::HTTP::Persistent
982
942
  # If a block is passed #request behaves like Net::HTTP#request (the body of
983
943
  # the response will not have been read).
984
944
  #
985
- # +req+ must be a Net::HTTPRequest subclass (see Net::HTTP for a list).
945
+ # +req+ must be a Net::HTTPGenericRequest subclass (see Net::HTTP for a list).
986
946
  #
987
947
  # If there is an error and the request is idempotent according to RFC 2616
988
948
  # it will be retried automatically.
@@ -991,52 +951,56 @@ class Bundler::Persistent::Net::HTTP::Persistent
991
951
  retried = false
992
952
  bad_response = false
993
953
 
994
- req = request_setup req || uri
954
+ uri = URI uri
955
+ req = request_setup req || uri
956
+ response = nil
995
957
 
996
- connection = connection_for uri
997
- connection_id = connection.object_id
958
+ connection_for uri do |connection|
959
+ http = connection.http
998
960
 
999
- begin
1000
- Thread.current[@request_key][connection_id] += 1
1001
- response = connection.request req, &block
961
+ begin
962
+ connection.requests += 1
1002
963
 
1003
- if connection_close?(req) or
1004
- (response.http_version <= '1.0' and
1005
- not connection_keep_alive?(response)) or
1006
- connection_close?(response) then
1007
- connection.finish
1008
- end
1009
- rescue Net::HTTPBadResponse => e
1010
- message = error_message connection
964
+ response = http.request req, &block
1011
965
 
1012
- finish connection
966
+ if req.connection_close? or
967
+ (response.http_version <= '1.0' and
968
+ not response.connection_keep_alive?) or
969
+ response.connection_close? then
970
+ finish connection
971
+ end
972
+ rescue Net::HTTPBadResponse => e
973
+ message = error_message connection
1013
974
 
1014
- raise Error, "too many bad responses #{message}" if
975
+ finish connection
976
+
977
+ raise Error, "too many bad responses #{message}" if
1015
978
  bad_response or not can_retry? req
1016
979
 
1017
- bad_response = true
1018
- retry
1019
- rescue *RETRIED_EXCEPTIONS => e # retried on ruby 2
1020
- request_failed e, req, connection if
1021
- retried or not can_retry? req, @retried_on_ruby_2
980
+ bad_response = true
981
+ retry
982
+ rescue *RETRIED_EXCEPTIONS => e
983
+ request_failed e, req, connection if
984
+ retried or not can_retry? req
1022
985
 
1023
- reset connection
986
+ reset connection
1024
987
 
1025
- retried = true
1026
- retry
1027
- rescue Errno::EINVAL, Errno::ETIMEDOUT => e # not retried on ruby 2
1028
- request_failed e, req, connection if retried or not can_retry? req
988
+ retried = true
989
+ retry
990
+ rescue Errno::EINVAL, Errno::ETIMEDOUT => e # not retried on ruby 2
991
+ request_failed e, req, connection if retried or not can_retry? req
1029
992
 
1030
- reset connection
993
+ reset connection
1031
994
 
1032
- retried = true
1033
- retry
1034
- rescue Exception => e
1035
- finish connection
995
+ retried = true
996
+ retry
997
+ rescue Exception => e
998
+ finish connection
1036
999
 
1037
- raise
1038
- ensure
1039
- Thread.current[@timeout_key][connection_id] = Time.now
1000
+ raise
1001
+ ensure
1002
+ connection.last_use = Time.now
1003
+ end
1040
1004
  end
1041
1005
 
1042
1006
  @http_versions["#{uri.host}:#{uri.port}"] ||= response.http_version
@@ -1056,7 +1020,6 @@ class Bundler::Persistent::Net::HTTP::Persistent
1056
1020
 
1057
1021
  finish connection
1058
1022
 
1059
-
1060
1023
  raise Error, message, exception.backtrace
1061
1024
  end
1062
1025
 
@@ -1090,45 +1053,15 @@ class Bundler::Persistent::Net::HTTP::Persistent
1090
1053
  end
1091
1054
 
1092
1055
  ##
1093
- # Shuts down all connections for +thread+.
1094
- #
1095
- # Uses the current thread by default.
1056
+ # Shuts down all connections
1096
1057
  #
1097
- # If you've used Bundler::Persistent::Net::HTTP::Persistent across multiple threads you should
1098
- # call this in each thread when you're done making HTTP requests.
1058
+ # *NOTE*: Calling shutdown for can be dangerous!
1099
1059
  #
1100
- # *NOTE*: Calling shutdown for another thread can be dangerous!
1101
- #
1102
- # If the thread is still using the connection it may cause an error! It is
1103
- # best to call #shutdown in the thread at the appropriate time instead!
1104
-
1105
- def shutdown thread = Thread.current
1106
- generation = reconnect
1107
- cleanup generation, thread, @generation_key
1108
-
1109
- ssl_generation = reconnect_ssl
1110
- cleanup ssl_generation, thread, @ssl_generation_key
1060
+ # If any thread is still using a connection it may cause an error! Call
1061
+ # #shutdown when you are completely done making requests!
1111
1062
 
1112
- thread[@request_key] = nil
1113
- thread[@timeout_key] = nil
1114
- end
1115
-
1116
- ##
1117
- # Shuts down all connections in all threads
1118
- #
1119
- # *NOTE*: THIS METHOD IS VERY DANGEROUS!
1120
- #
1121
- # Do not call this method if other threads are still using their
1122
- # connections! Call #shutdown at the appropriate time instead!
1123
- #
1124
- # Use this method only as a last resort!
1125
-
1126
- def shutdown_in_all_threads
1127
- Thread.list.each do |thread|
1128
- shutdown thread
1129
- end
1130
-
1131
- nil
1063
+ def shutdown
1064
+ @pool.shutdown { |http| http.finish }
1132
1065
  end
1133
1066
 
1134
1067
  ##
@@ -1137,9 +1070,14 @@ class Bundler::Persistent::Net::HTTP::Persistent
1137
1070
  def ssl connection
1138
1071
  connection.use_ssl = true
1139
1072
 
1073
+ connection.ciphers = @ciphers if @ciphers
1074
+ connection.ssl_timeout = @ssl_timeout if @ssl_timeout
1140
1075
  connection.ssl_version = @ssl_version if @ssl_version
1076
+ connection.min_version = @min_version if @min_version
1077
+ connection.max_version = @max_version if @max_version
1141
1078
 
1142
- connection.verify_mode = @verify_mode
1079
+ connection.verify_depth = @verify_depth
1080
+ connection.verify_mode = @verify_mode
1143
1081
 
1144
1082
  if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
1145
1083
  not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
@@ -1168,8 +1106,10 @@ application:
1168
1106
  WARNING
1169
1107
  end
1170
1108
 
1171
- if @ca_file then
1172
- connection.ca_file = @ca_file
1109
+ connection.ca_file = @ca_file if @ca_file
1110
+ connection.ca_path = @ca_path if @ca_path
1111
+
1112
+ if @ca_file or @ca_path then
1173
1113
  connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
1174
1114
  connection.verify_callback = @verify_callback if @verify_callback
1175
1115
  end
@@ -1189,11 +1129,12 @@ application:
1189
1129
  end
1190
1130
 
1191
1131
  ##
1192
- # Finishes all connections that existed before the given SSL parameter
1193
- # +generation+.
1132
+ # SSL session lifetime
1194
1133
 
1195
- def ssl_cleanup generation # :nodoc:
1196
- cleanup generation, Thread.current, @ssl_generation_key
1134
+ def ssl_timeout= ssl_timeout
1135
+ @ssl_timeout = ssl_timeout
1136
+
1137
+ reconnect_ssl
1197
1138
  end
1198
1139
 
1199
1140
  ##
@@ -1203,7 +1144,34 @@ application:
1203
1144
  @ssl_version = ssl_version
1204
1145
 
1205
1146
  reconnect_ssl
1206
- end if RUBY_VERSION > '1.9'
1147
+ end
1148
+
1149
+ ##
1150
+ # Minimum SSL version to use
1151
+
1152
+ def min_version= min_version
1153
+ @min_version = min_version
1154
+
1155
+ reconnect_ssl
1156
+ end
1157
+
1158
+ ##
1159
+ # maximum SSL version to use
1160
+
1161
+ def max_version= max_version
1162
+ @max_version = max_version
1163
+
1164
+ reconnect_ssl
1165
+ end
1166
+
1167
+ ##
1168
+ # Sets the depth of SSL certificate verification
1169
+
1170
+ def verify_depth= verify_depth
1171
+ @verify_depth = verify_depth
1172
+
1173
+ reconnect_ssl
1174
+ end
1207
1175
 
1208
1176
  ##
1209
1177
  # Sets the HTTPS verify mode. Defaults to OpenSSL::SSL::VERIFY_PEER.
@@ -1229,5 +1197,6 @@ application:
1229
1197
 
1230
1198
  end
1231
1199
 
1232
- require 'bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse'
1200
+ require_relative 'persistent/connection'
1201
+ require_relative 'persistent/pool'
1233
1202