bundler 2.0.1 → 2.1.4

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 (249) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +788 -572
  3. data/LICENSE.md +18 -19
  4. data/README.md +9 -8
  5. data/bundler.gemspec +8 -25
  6. data/exe/bundle +19 -3
  7. data/lib/bundler.rb +202 -87
  8. data/lib/bundler/build_metadata.rb +3 -3
  9. data/lib/bundler/capistrano.rb +5 -5
  10. data/lib/bundler/cli.rb +182 -144
  11. data/lib/bundler/cli/add.rb +28 -16
  12. data/lib/bundler/cli/cache.rb +25 -13
  13. data/lib/bundler/cli/common.rb +11 -12
  14. data/lib/bundler/cli/config.rb +161 -86
  15. data/lib/bundler/cli/console.rb +2 -2
  16. data/lib/bundler/cli/doctor.rb +4 -4
  17. data/lib/bundler/cli/exec.rb +4 -16
  18. data/lib/bundler/cli/gem.rb +5 -5
  19. data/lib/bundler/cli/info.rb +17 -5
  20. data/lib/bundler/cli/init.rb +1 -1
  21. data/lib/bundler/cli/install.rb +15 -13
  22. data/lib/bundler/cli/issue.rb +3 -3
  23. data/lib/bundler/cli/open.rb +10 -6
  24. data/lib/bundler/cli/outdated.rb +85 -81
  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 +31 -11
  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 +36 -27
  33. data/lib/bundler/dependency.rb +16 -4
  34. data/lib/bundler/deployment.rb +2 -2
  35. data/lib/bundler/dsl.rb +19 -43
  36. data/lib/bundler/env.rb +8 -13
  37. data/lib/bundler/environment_preserver.rb +0 -1
  38. data/lib/bundler/feature_flag.rb +2 -14
  39. data/lib/bundler/fetcher.rb +16 -13
  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 +5 -2
  43. data/lib/bundler/fetcher/index.rb +5 -3
  44. data/lib/bundler/friendly_errors.rb +6 -7
  45. data/lib/bundler/gem_helper.rb +39 -25
  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 +10 -8
  51. data/lib/bundler/inline.rb +40 -30
  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 -8
  55. data/lib/bundler/installer/standalone.rb +1 -2
  56. data/lib/bundler/lazy_specification.rb +2 -3
  57. data/lib/bundler/lockfile_parser.rb +14 -21
  58. data/lib/bundler/match_platform.rb +1 -1
  59. data/lib/bundler/mirror.rb +3 -3
  60. data/lib/bundler/plugin.rb +42 -29
  61. data/lib/bundler/plugin/api.rb +1 -1
  62. data/lib/bundler/plugin/api/source.rb +4 -6
  63. data/lib/bundler/plugin/index.rb +14 -3
  64. data/lib/bundler/plugin/installer.rb +28 -15
  65. data/lib/bundler/psyched_yaml.rb +1 -1
  66. data/lib/bundler/remote_specification.rb +0 -2
  67. data/lib/bundler/resolver.rb +72 -24
  68. data/lib/bundler/resolver/spec_group.rb +3 -2
  69. data/lib/bundler/retry.rb +2 -2
  70. data/lib/bundler/ruby_version.rb +4 -19
  71. data/lib/bundler/rubygems_ext.rb +11 -67
  72. data/lib/bundler/rubygems_gem_installer.rb +1 -1
  73. data/lib/bundler/rubygems_integration.rb +149 -399
  74. data/lib/bundler/runtime.rb +2 -9
  75. data/lib/bundler/settings.rb +22 -52
  76. data/lib/bundler/setup.rb +11 -12
  77. data/lib/bundler/shared_helpers.rb +51 -77
  78. data/lib/bundler/similarity_detector.rb +2 -2
  79. data/lib/bundler/source.rb +5 -5
  80. data/lib/bundler/source/git.rb +24 -17
  81. data/lib/bundler/source/git/git_proxy.rb +38 -41
  82. data/lib/bundler/source/metadata.rb +7 -2
  83. data/lib/bundler/source/path.rb +13 -8
  84. data/lib/bundler/source/rubygems.rb +14 -8
  85. data/lib/bundler/source/rubygems/remote.rb +2 -3
  86. data/lib/bundler/source_list.rb +9 -12
  87. data/lib/bundler/spec_set.rb +1 -6
  88. data/lib/bundler/stub_specification.rb +18 -30
  89. data/lib/bundler/templates/Executable.bundler +23 -14
  90. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +3 -3
  91. data/lib/bundler/templates/newgem/Gemfile.tt +8 -0
  92. data/lib/bundler/templates/newgem/README.md.tt +4 -3
  93. data/lib/bundler/templates/newgem/newgem.gemspec.tt +6 -27
  94. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +1 -1
  95. data/lib/bundler/templates/newgem/travis.yml.tt +0 -1
  96. data/lib/bundler/ui.rb +3 -3
  97. data/lib/bundler/ui/rg_proxy.rb +1 -1
  98. data/lib/bundler/ui/shell.rb +4 -8
  99. data/lib/bundler/uri_credentials_filter.rb +7 -3
  100. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +161 -0
  101. data/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +66 -0
  102. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +176 -0
  103. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +3 -0
  104. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +273 -147
  105. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +6 -6
  106. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  107. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +1 -1
  108. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +1 -1
  109. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +1 -1
  110. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +1 -1
  111. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +6 -6
  112. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +1 -1
  113. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +1 -1
  114. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +30 -8
  115. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +1 -1
  116. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +4 -4
  117. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +2 -2
  118. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +270 -323
  119. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +40 -0
  120. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +53 -0
  121. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +79 -0
  122. data/lib/bundler/vendor/thor/lib/thor.rb +19 -4
  123. data/lib/bundler/vendor/thor/lib/thor/actions.rb +27 -12
  124. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +1 -1
  125. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +1 -1
  126. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +7 -17
  127. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +16 -7
  128. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +19 -8
  129. data/lib/bundler/vendor/thor/lib/thor/base.rb +54 -43
  130. data/lib/bundler/vendor/thor/lib/thor/command.rb +21 -14
  131. data/lib/bundler/vendor/thor/lib/thor/error.rb +78 -0
  132. data/lib/bundler/vendor/thor/lib/thor/group.rb +3 -3
  133. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +1 -0
  134. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +2 -2
  135. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +1 -1
  136. data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +6 -6
  137. data/lib/bundler/vendor/thor/lib/thor/nested_context.rb +29 -0
  138. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -4
  139. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +2 -2
  140. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +20 -7
  141. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +20 -5
  142. data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +1 -0
  143. data/lib/bundler/vendor/thor/lib/thor/runner.rb +15 -14
  144. data/lib/bundler/vendor/thor/lib/thor/shell.rb +4 -4
  145. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +62 -8
  146. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +6 -2
  147. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +3 -3
  148. data/lib/bundler/vendor/thor/lib/thor/util.rb +18 -2
  149. data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  150. data/lib/bundler/vendor/uri/lib/uri.rb +104 -0
  151. data/lib/bundler/vendor/uri/lib/uri/common.rb +744 -0
  152. data/lib/bundler/vendor/uri/lib/uri/file.rb +94 -0
  153. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +267 -0
  154. data/lib/bundler/vendor/uri/lib/uri/generic.rb +1568 -0
  155. data/lib/bundler/vendor/uri/lib/uri/http.rb +88 -0
  156. data/lib/bundler/vendor/uri/lib/uri/https.rb +23 -0
  157. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +261 -0
  158. data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +21 -0
  159. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +294 -0
  160. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +546 -0
  161. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +125 -0
  162. data/lib/bundler/vendor/uri/lib/uri/version.rb +6 -0
  163. data/lib/bundler/vendored_fileutils.rb +1 -6
  164. data/lib/bundler/vendored_molinillo.rb +1 -1
  165. data/lib/bundler/vendored_persistent.rb +7 -5
  166. data/lib/bundler/vendored_thor.rb +2 -2
  167. data/lib/bundler/vendored_uri.rb +4 -0
  168. data/lib/bundler/version.rb +1 -20
  169. data/lib/bundler/version_ranges.rb +51 -5
  170. data/lib/bundler/vlad.rb +3 -3
  171. data/lib/bundler/worker.rb +1 -3
  172. data/lib/bundler/yaml_serializer.rb +2 -3
  173. data/man/bundle-add.1 +10 -2
  174. data/man/bundle-add.1.txt +11 -5
  175. data/man/bundle-add.ronn +7 -1
  176. data/man/bundle-binstubs.1 +2 -2
  177. data/man/bundle-binstubs.1.txt +2 -2
  178. data/man/bundle-binstubs.ronn +1 -1
  179. data/man/bundle-cache.1 +55 -0
  180. data/man/bundle-cache.1.txt +78 -0
  181. data/man/{bundle-package.ronn → bundle-cache.ronn} +15 -15
  182. data/man/bundle-check.1 +1 -1
  183. data/man/bundle-check.1.txt +6 -6
  184. data/man/bundle-clean.1 +1 -1
  185. data/man/bundle-clean.1.txt +1 -1
  186. data/man/bundle-config.1 +36 -36
  187. data/man/bundle-config.1.txt +66 -67
  188. data/man/bundle-config.ronn +42 -40
  189. data/man/bundle-doctor.1 +1 -1
  190. data/man/bundle-doctor.1.txt +1 -1
  191. data/man/bundle-exec.1 +2 -2
  192. data/man/bundle-exec.1.txt +2 -2
  193. data/man/bundle-exec.ronn +1 -1
  194. data/man/bundle-gem.1 +1 -1
  195. data/man/bundle-gem.1.txt +3 -3
  196. data/man/bundle-info.1 +1 -1
  197. data/man/bundle-info.1.txt +1 -1
  198. data/man/bundle-init.1 +2 -2
  199. data/man/bundle-init.1.txt +2 -2
  200. data/man/bundle-init.ronn +1 -1
  201. data/man/bundle-inject.1 +1 -1
  202. data/man/bundle-inject.1.txt +1 -1
  203. data/man/bundle-install.1 +8 -5
  204. data/man/bundle-install.1.txt +56 -51
  205. data/man/bundle-install.ronn +9 -4
  206. data/man/bundle-list.1 +1 -1
  207. data/man/bundle-list.1.txt +1 -1
  208. data/man/bundle-lock.1 +1 -1
  209. data/man/bundle-lock.1.txt +16 -16
  210. data/man/bundle-open.1 +1 -1
  211. data/man/bundle-open.1.txt +1 -1
  212. data/man/bundle-outdated.1 +1 -1
  213. data/man/bundle-outdated.1.txt +1 -1
  214. data/man/bundle-platform.1 +1 -1
  215. data/man/bundle-platform.1.txt +1 -1
  216. data/man/bundle-pristine.1 +1 -1
  217. data/man/bundle-pristine.1.txt +1 -1
  218. data/man/bundle-remove.1 +1 -1
  219. data/man/bundle-remove.1.txt +1 -1
  220. data/man/bundle-show.1 +1 -1
  221. data/man/bundle-show.1.txt +1 -1
  222. data/man/bundle-update.1 +4 -4
  223. data/man/bundle-update.1.txt +64 -65
  224. data/man/bundle-update.ronn +3 -3
  225. data/man/bundle-viz.1 +1 -1
  226. data/man/bundle-viz.1.txt +1 -1
  227. data/man/bundle.1 +3 -3
  228. data/man/bundle.1.txt +8 -8
  229. data/man/bundle.ronn +2 -2
  230. data/man/gemfile.5 +13 -16
  231. data/man/gemfile.5.ronn +10 -14
  232. data/man/gemfile.5.txt +104 -108
  233. data/man/index.txt +1 -1
  234. metadata +33 -108
  235. data/exe/bundle_ruby +0 -60
  236. data/lib/bundler/cli/package.rb +0 -49
  237. data/lib/bundler/compatibility_guard.rb +0 -14
  238. data/lib/bundler/gem_remote_fetcher.rb +0 -43
  239. data/lib/bundler/ssl_certs/.document +0 -1
  240. data/lib/bundler/ssl_certs/certificate_manager.rb +0 -66
  241. data/lib/bundler/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem +0 -21
  242. data/lib/bundler/ssl_certs/rubygems.global.ssl.fastly.net/DigiCertHighAssuranceEVRootCA.pem +0 -23
  243. data/lib/bundler/ssl_certs/rubygems.org/AddTrustExternalCARoot.pem +0 -25
  244. data/lib/bundler/vendor/net-http-persistent/lib/net/http/faster.rb +0 -27
  245. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse.rb +0 -129
  246. data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +0 -12
  247. data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +0 -129
  248. data/man/bundle-package.1 +0 -55
  249. data/man/bundle-package.1.txt +0 -79
@@ -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,17 +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
- require 'uri'
2
+ require_relative '../../../../uri/lib/uri'
9
3
  require 'cgi' # for escaping
10
-
11
- begin
12
- require 'net/http/pipeline'
13
- rescue LoadError
14
- end
4
+ require_relative '../../../../connection_pool/lib/connection_pool'
15
5
 
16
6
  autoload :OpenSSL, 'openssl'
17
7
 
@@ -36,9 +26,9 @@ autoload :OpenSSL, 'openssl'
36
26
  #
37
27
  # require 'bundler/vendor/net-http-persistent/lib/net/http/persistent'
38
28
  #
39
- # uri = URI 'http://example.com/awesome/web/service'
29
+ # uri = Bundler::URI 'http://example.com/awesome/web/service'
40
30
  #
41
- # http = Bundler::Persistent::Net::HTTP::Persistent.new 'my_app_name'
31
+ # http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name'
42
32
  #
43
33
  # # perform a GET
44
34
  # response = http.request uri
@@ -53,36 +43,40 @@ autoload :OpenSSL, 'openssl'
53
43
  # post = Net::HTTP::Post.new post_uri.path
54
44
  # post.set_form_data 'some' => 'cool data'
55
45
  #
56
- # # perform the POST, the URI is always required
46
+ # # perform the POST, the Bundler::URI is always required
57
47
  # response http.request post_uri, post
58
48
  #
59
49
  # Note that for GET, HEAD and other requests that do not have a body you want
60
- # to use URI#request_uri not URI#path. The request_uri contains the query
50
+ # to use Bundler::URI#request_uri not Bundler::URI#path. The request_uri contains the query
61
51
  # params which are sent in the body for other requests.
62
52
  #
63
53
  # == SSL
64
54
  #
65
55
  # SSL connections are automatically created depending upon the scheme of the
66
- # URI. SSL connections are automatically verified against the default
56
+ # Bundler::URI. SSL connections are automatically verified against the default
67
57
  # certificate store for your computer. You can override this by changing
68
58
  # verify_mode or by specifying an alternate cert_store.
69
59
  #
70
60
  # Here are the SSL settings, see the individual methods for documentation:
71
61
  #
72
62
  # #certificate :: This client's certificate
73
- # #ca_file :: The certificate-authority
63
+ # #ca_file :: The certificate-authorities
64
+ # #ca_path :: Directory with certificate-authorities
74
65
  # #cert_store :: An SSL certificate store
66
+ # #ciphers :: List of SSl ciphers allowed
75
67
  # #private_key :: The client's SSL private key
76
68
  # #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new
77
69
  # connection
70
+ # #ssl_timeout :: SSL session lifetime
78
71
  # #ssl_version :: Which specific SSL version to use
79
72
  # #verify_callback :: For server certificate verification
73
+ # #verify_depth :: Depth of certificate verification
80
74
  # #verify_mode :: How connections should be verified
81
75
  #
82
76
  # == Proxies
83
77
  #
84
78
  # A proxy can be set through #proxy= or at initialization time by providing a
85
- # second argument to ::new. The proxy may be the URI of the proxy server or
79
+ # second argument to ::new. The proxy may be the Bundler::URI of the proxy server or
86
80
  # <code>:ENV</code> which will consult environment variables.
87
81
  #
88
82
  # See #proxy= and #proxy_from_env for details.
@@ -151,10 +145,10 @@ autoload :OpenSSL, 'openssl'
151
145
  #
152
146
  # require 'bundler/vendor/net-http-persistent/lib/net/http/persistent'
153
147
  #
154
- # uri = URI 'http://example.com/awesome/web/service'
148
+ # uri = Bundler::URI 'http://example.com/awesome/web/service'
155
149
  # post_uri = uri + 'create'
156
150
  #
157
- # http = Bundler::Persistent::Net::HTTP::Persistent.new 'my_app_name'
151
+ # http = Bundler::Persistent::Net::HTTP::Persistent.new name: 'my_app_name'
158
152
  #
159
153
  # post = Net::HTTP::Post.new post_uri.path
160
154
  # # ... fill in POST request
@@ -200,10 +194,19 @@ class Bundler::Persistent::Net::HTTP::Persistent
200
194
 
201
195
  HAVE_OPENSSL = defined? OpenSSL::SSL # :nodoc:
202
196
 
197
+ ##
198
+ # The default connection pool size is 1/4 the allowed open files.
199
+
200
+ if Gem.win_platform? then
201
+ DEFAULT_POOL_SIZE = 256
202
+ else
203
+ DEFAULT_POOL_SIZE = Process.getrlimit(Process::RLIMIT_NOFILE).first / 4
204
+ end
205
+
203
206
  ##
204
207
  # The version of Bundler::Persistent::Net::HTTP::Persistent you are using
205
208
 
206
- VERSION = '2.9.4'
209
+ VERSION = '3.1.0'
207
210
 
208
211
  ##
209
212
  # Exceptions rescued for automatic retry on ruby 2.0.0. This overlaps with
@@ -241,38 +244,38 @@ class Bundler::Persistent::Net::HTTP::Persistent
241
244
  # NOTE: This may not work on ruby > 1.9.
242
245
 
243
246
  def self.detect_idle_timeout uri, max = 10
244
- uri = URI uri unless URI::Generic === uri
247
+ uri = Bundler::URI uri unless Bundler::URI::Generic === uri
245
248
  uri += '/'
246
249
 
247
250
  req = Net::HTTP::Head.new uri.request_uri
248
251
 
249
252
  http = new 'net-http-persistent detect_idle_timeout'
250
253
 
251
- connection = http.connection_for uri
254
+ http.connection_for uri do |connection|
255
+ sleep_time = 0
252
256
 
253
- sleep_time = 0
257
+ http = connection.http
254
258
 
255
- loop do
256
- response = connection.request req
259
+ loop do
260
+ response = http.request req
257
261
 
258
- $stderr.puts "HEAD #{uri} => #{response.code}" if $DEBUG
262
+ $stderr.puts "HEAD #{uri} => #{response.code}" if $DEBUG
259
263
 
260
- unless Net::HTTPOK === response then
261
- raise Error, "bad response code #{response.code} detecting idle timeout"
262
- end
264
+ unless Net::HTTPOK === response then
265
+ raise Error, "bad response code #{response.code} detecting idle timeout"
266
+ end
263
267
 
264
- break if sleep_time >= max
268
+ break if sleep_time >= max
265
269
 
266
- sleep_time += 1
270
+ sleep_time += 1
267
271
 
268
- $stderr.puts "sleeping #{sleep_time}" if $DEBUG
269
- sleep sleep_time
272
+ $stderr.puts "sleeping #{sleep_time}" if $DEBUG
273
+ sleep sleep_time
274
+ end
270
275
  end
271
276
  rescue
272
277
  # ignore StandardErrors, we've probably found the idle timeout.
273
278
  ensure
274
- http.shutdown
275
-
276
279
  return sleep_time unless $!
277
280
  end
278
281
 
@@ -281,7 +284,9 @@ class Bundler::Persistent::Net::HTTP::Persistent
281
284
 
282
285
  attr_reader :certificate
283
286
 
287
+ ##
284
288
  # For Net::HTTP parity
289
+
285
290
  alias cert certificate
286
291
 
287
292
  ##
@@ -290,12 +295,23 @@ class Bundler::Persistent::Net::HTTP::Persistent
290
295
 
291
296
  attr_reader :ca_file
292
297
 
298
+ ##
299
+ # A directory of SSL certificates to be used as certificate authorities.
300
+ # Setting this will set verify_mode to VERIFY_PEER.
301
+
302
+ attr_reader :ca_path
303
+
293
304
  ##
294
305
  # An SSL certificate store. Setting this will override the default
295
306
  # certificate store. See verify_mode for more information.
296
307
 
297
308
  attr_reader :cert_store
298
309
 
310
+ ##
311
+ # The ciphers allowed for SSL connections
312
+
313
+ attr_reader :ciphers
314
+
299
315
  ##
300
316
  # Sends debug_output to this IO via Net::HTTP#set_debug_output.
301
317
  #
@@ -309,11 +325,6 @@ class Bundler::Persistent::Net::HTTP::Persistent
309
325
 
310
326
  attr_reader :generation # :nodoc:
311
327
 
312
- ##
313
- # Where this instance's connections live in the thread local variables
314
-
315
- attr_reader :generation_key # :nodoc:
316
-
317
328
  ##
318
329
  # Headers that are added to every request using Net::HTTP#add_field
319
330
 
@@ -369,7 +380,9 @@ class Bundler::Persistent::Net::HTTP::Persistent
369
380
 
370
381
  attr_reader :private_key
371
382
 
383
+ ##
372
384
  # For Net::HTTP parity
385
+
373
386
  alias key private_key
374
387
 
375
388
  ##
@@ -382,15 +395,20 @@ class Bundler::Persistent::Net::HTTP::Persistent
382
395
 
383
396
  attr_reader :no_proxy
384
397
 
398
+ ##
399
+ # Test-only accessor for the connection pool
400
+
401
+ attr_reader :pool # :nodoc:
402
+
385
403
  ##
386
404
  # Seconds to wait until reading one block. See Net::HTTP#read_timeout
387
405
 
388
406
  attr_accessor :read_timeout
389
407
 
390
408
  ##
391
- # Where this instance's request counts live in the thread local variables
409
+ # Seconds to wait until writing one block. See Net::HTTP#write_timeout
392
410
 
393
- attr_reader :request_key # :nodoc:
411
+ attr_accessor :write_timeout
394
412
 
395
413
  ##
396
414
  # By default SSL sessions are reused to avoid extra SSL handshakes. Set
@@ -418,17 +436,33 @@ class Bundler::Persistent::Net::HTTP::Persistent
418
436
  attr_reader :ssl_generation # :nodoc:
419
437
 
420
438
  ##
421
- # Where this instance's SSL connections live in the thread local variables
439
+ # SSL session lifetime
422
440
 
423
- attr_reader :ssl_generation_key # :nodoc:
441
+ attr_reader :ssl_timeout
424
442
 
425
443
  ##
426
444
  # SSL version to use.
427
445
  #
428
446
  # By default, the version will be negotiated automatically between client
429
- # and server. Ruby 1.9 and newer only.
447
+ # and server. Ruby 1.9 and newer only. Deprecated since Ruby 2.5.
448
+
449
+ attr_reader :ssl_version
450
+
451
+ ##
452
+ # Minimum SSL version to use, e.g. :TLS1_1
453
+ #
454
+ # By default, the version will be negotiated automatically between client
455
+ # and server. Ruby 2.5 and newer only.
456
+
457
+ attr_reader :min_version
458
+
459
+ ##
460
+ # Maximum SSL version to use, e.g. :TLS1_2
461
+ #
462
+ # By default, the version will be negotiated automatically between client
463
+ # and server. Ruby 2.5 and newer only.
430
464
 
431
- attr_reader :ssl_version if RUBY_VERSION > '1.9'
465
+ attr_reader :max_version
432
466
 
433
467
  ##
434
468
  # Where this instance's last-use times live in the thread local variables
@@ -436,16 +470,21 @@ class Bundler::Persistent::Net::HTTP::Persistent
436
470
  attr_reader :timeout_key # :nodoc:
437
471
 
438
472
  ##
439
- # SSL verification callback. Used when ca_file is set.
473
+ # SSL verification callback. Used when ca_file or ca_path is set.
440
474
 
441
475
  attr_reader :verify_callback
442
476
 
477
+ ##
478
+ # Sets the depth of SSL certificate verification
479
+
480
+ attr_reader :verify_depth
481
+
443
482
  ##
444
483
  # HTTPS verify mode. Defaults to OpenSSL::SSL::VERIFY_PEER which verifies
445
484
  # the server certificate.
446
485
  #
447
- # If no ca_file or cert_store is set the default system certificate store is
448
- # used.
486
+ # If no ca_file, ca_path or cert_store is set the default system certificate
487
+ # store is used.
449
488
  #
450
489
  # You can use +verify_mode+ to override any default values.
451
490
 
@@ -469,17 +508,21 @@ class Bundler::Persistent::Net::HTTP::Persistent
469
508
  # required currently, but highly recommended. Your library name should be
470
509
  # good enough. This parameter will be required in a future version.
471
510
  #
472
- # +proxy+ may be set to a URI::HTTP or :ENV to pick up proxy options from
511
+ # +proxy+ may be set to a Bundler::URI::HTTP or :ENV to pick up proxy options from
473
512
  # the environment. See proxy_from_env for details.
474
513
  #
475
- # In order to use a URI for the proxy you may need to do some extra work
476
- # beyond URI parsing if the proxy requires a password:
514
+ # In order to use a Bundler::URI for the proxy you may need to do some extra work
515
+ # beyond Bundler::URI parsing if the proxy requires a password:
477
516
  #
478
- # proxy = URI 'http://proxy.example'
517
+ # proxy = Bundler::URI 'http://proxy.example'
479
518
  # proxy.user = 'AzureDiamond'
480
519
  # proxy.password = 'hunter2'
520
+ #
521
+ # Set +pool_size+ to limit the maximum number of connections allowed.
522
+ # Defaults to 1/4 the number of allowed file handles. You can have no more
523
+ # than this many threads with active HTTP transactions.
481
524
 
482
- def initialize name = nil, proxy = nil
525
+ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
483
526
  @name = name
484
527
 
485
528
  @debug_output = nil
@@ -491,29 +534,34 @@ class Bundler::Persistent::Net::HTTP::Persistent
491
534
  @keep_alive = 30
492
535
  @open_timeout = nil
493
536
  @read_timeout = nil
537
+ @write_timeout = nil
494
538
  @idle_timeout = 5
495
539
  @max_requests = nil
496
540
  @socket_options = []
541
+ @ssl_generation = 0 # incremented when SSL session variables change
497
542
 
498
543
  @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
499
544
  Socket.const_defined? :TCP_NODELAY
500
545
 
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
546
+ @pool = Bundler::Persistent::Net::HTTP::Persistent::Pool.new size: pool_size do |http_args|
547
+ Bundler::Persistent::Net::HTTP::Persistent::Connection.new Net::HTTP, http_args, @ssl_generation
548
+ end
506
549
 
507
550
  @certificate = nil
508
551
  @ca_file = nil
552
+ @ca_path = nil
553
+ @ciphers = nil
509
554
  @private_key = nil
555
+ @ssl_timeout = nil
510
556
  @ssl_version = nil
557
+ @min_version = nil
558
+ @max_version = nil
511
559
  @verify_callback = nil
560
+ @verify_depth = nil
512
561
  @verify_mode = nil
513
562
  @cert_store = nil
514
563
 
515
- @generation = 0 # incremented when proxy URI changes
516
- @ssl_generation = 0 # incremented when SSL session variables change
564
+ @generation = 0 # incremented when proxy Bundler::URI changes
517
565
 
518
566
  if HAVE_OPENSSL then
519
567
  @verify_mode = OpenSSL::SSL::VERIFY_PEER
@@ -522,9 +570,6 @@ class Bundler::Persistent::Net::HTTP::Persistent
522
570
 
523
571
  @retry_change_requests = false
524
572
 
525
- @ruby_1 = RUBY_VERSION < '2'
526
- @retried_on_ruby_2 = !@ruby_1
527
-
528
573
  self.proxy = proxy if proxy
529
574
  end
530
575
 
@@ -549,6 +594,15 @@ class Bundler::Persistent::Net::HTTP::Persistent
549
594
  reconnect_ssl
550
595
  end
551
596
 
597
+ ##
598
+ # Sets the SSL certificate authority path.
599
+
600
+ def ca_path= path
601
+ @ca_path = path
602
+
603
+ reconnect_ssl
604
+ end
605
+
552
606
  ##
553
607
  # Overrides the default SSL certificate store used for verifying
554
608
  # connections.
@@ -560,92 +614,59 @@ class Bundler::Persistent::Net::HTTP::Persistent
560
614
  end
561
615
 
562
616
  ##
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]
617
+ # The ciphers allowed for SSL connections
571
618
 
572
- (0...generation).each do |old_generation|
573
- next unless thread[generation_key]
619
+ def ciphers= ciphers
620
+ @ciphers = ciphers
574
621
 
575
- conns = thread[generation_key].delete old_generation
576
-
577
- conns.each_value do |conn|
578
- finish conn, thread
579
-
580
- timeouts.delete conn.object_id if timeouts
581
- end if conns
582
- end
622
+ reconnect_ssl
583
623
  end
584
624
 
585
625
  ##
586
626
  # Creates a new connection for +uri+
587
627
 
588
628
  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
629
  use_ssl = uri.scheme.downcase == 'https'
595
630
 
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
603
-
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 ':'
631
+ net_http_args = [uri.hostname, uri.port]
615
632
 
616
- if @proxy_uri and not proxy_bypass? uri.host, uri.port then
617
- connection_id << @proxy_connection_id
633
+ if @proxy_uri and not proxy_bypass? uri.hostname, uri.port then
618
634
  net_http_args.concat @proxy_args
619
635
  else
620
636
  net_http_args.concat [nil, nil, nil, nil]
621
637
  end
622
638
 
623
- connection = connections[connection_id]
639
+ connection = @pool.checkout net_http_args
624
640
 
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
641
+ http = connection.http
642
+
643
+ connection.ressl @ssl_generation if
644
+ connection.ssl_generation != @ssl_generation
632
645
 
633
- start connection unless connection.started?
646
+ if not http.started? then
647
+ ssl http if use_ssl
648
+ start http
649
+ elsif expired? connection then
650
+ reset connection
651
+ end
634
652
 
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=)
653
+ http.read_timeout = @read_timeout if @read_timeout
654
+ http.write_timeout = @write_timeout if @write_timeout && http.respond_to?(:write_timeout=)
655
+ http.keep_alive_timeout = @idle_timeout if @idle_timeout
637
656
 
638
- connection
657
+ return yield connection
639
658
  rescue Errno::ECONNREFUSED
640
- address = connection.proxy_address || connection.address
641
- port = connection.proxy_port || connection.port
659
+ address = http.proxy_address || http.address
660
+ port = http.proxy_port || http.port
642
661
 
643
662
  raise Error, "connection refused: #{address}:#{port}"
644
663
  rescue Errno::EHOSTDOWN
645
- address = connection.proxy_address || connection.address
646
- port = connection.proxy_port || connection.port
664
+ address = http.proxy_address || http.address
665
+ port = http.proxy_port || http.port
647
666
 
648
667
  raise Error, "host down: #{address}:#{port}"
668
+ ensure
669
+ @pool.checkin net_http_args
649
670
  end
650
671
 
651
672
  ##
@@ -653,24 +674,23 @@ class Bundler::Persistent::Net::HTTP::Persistent
653
674
  # this connection
654
675
 
655
676
  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]
677
+ connection.requests -= 1 # fixup
658
678
 
659
- age = Time.now - last_use
679
+ age = Time.now - connection.last_use
660
680
 
661
- "after #{requests} requests on #{connection.object_id}, " \
681
+ "after #{connection.requests} requests on #{connection.http.object_id}, " \
662
682
  "last used #{age} seconds ago"
663
683
  end
664
684
 
665
685
  ##
666
- # URI::escape wrapper
686
+ # Bundler::URI::escape wrapper
667
687
 
668
688
  def escape str
669
689
  CGI.escape str if str
670
690
  end
671
691
 
672
692
  ##
673
- # URI::unescape wrapper
693
+ # Bundler::URI::unescape wrapper
674
694
 
675
695
  def unescape str
676
696
  CGI.unescape str if str
@@ -682,26 +702,23 @@ class Bundler::Persistent::Net::HTTP::Persistent
682
702
  # maximum request count, false otherwise.
683
703
 
684
704
  def expired? connection
685
- requests = Thread.current[@request_key][connection.object_id]
686
- return true if @max_requests && requests >= @max_requests
705
+ return true if @max_requests && connection.requests >= @max_requests
687
706
  return false unless @idle_timeout
688
707
  return true if @idle_timeout.zero?
689
708
 
690
- last_used = Thread.current[@timeout_key][connection.object_id]
691
-
692
- Time.now - last_used > @idle_timeout
709
+ Time.now - connection.last_use > @idle_timeout
693
710
  end
694
711
 
695
712
  ##
696
713
  # Starts the Net::HTTP +connection+
697
714
 
698
- def start connection
699
- connection.set_debug_output @debug_output if @debug_output
700
- connection.open_timeout = @open_timeout if @open_timeout
715
+ def start http
716
+ http.set_debug_output @debug_output if @debug_output
717
+ http.open_timeout = @open_timeout if @open_timeout
701
718
 
702
- connection.start
719
+ http.start
703
720
 
704
- socket = connection.instance_variable_get :@socket
721
+ socket = http.instance_variable_get :@socket
705
722
 
706
723
  if socket then # for fakeweb
707
724
  @socket_options.each do |option|
@@ -713,25 +730,11 @@ class Bundler::Persistent::Net::HTTP::Persistent
713
730
  ##
714
731
  # Finishes the Net::HTTP +connection+
715
732
 
716
- def finish connection, thread = Thread.current
717
- if requests = thread[@request_key] then
718
- requests.delete connection.object_id
719
- end
720
-
733
+ def finish connection
721
734
  connection.finish
722
- rescue IOError
723
- end
724
735
 
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
736
+ connection.http.instance_variable_set :@ssl_session, nil unless
737
+ @reuse_ssl_sessions
735
738
  end
736
739
 
737
740
  ##
@@ -745,64 +748,17 @@ class Bundler::Persistent::Net::HTTP::Persistent
745
748
  # Is +req+ idempotent according to RFC 2616?
746
749
 
747
750
  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
751
+ case req.method
752
+ when 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE' then
751
753
  true
752
754
  end
753
755
  end
754
756
 
755
757
  ##
756
758
  # 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
-
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
759
 
805
- Time.now - @idle_timeout
760
+ def can_retry? req
761
+ @retry_change_requests && !idempotent?(req)
806
762
  end
807
763
 
808
764
  ##
@@ -812,23 +768,6 @@ class Bundler::Persistent::Net::HTTP::Persistent
812
768
  (uri =~ /^https?:/) ? uri : "http://#{uri}"
813
769
  end
814
770
 
815
- ##
816
- # Pipelines +requests+ to the HTTP server at +uri+ yielding responses if a
817
- # block is given. Returns all responses received.
818
- #
819
- # See
820
- # Net::HTTP::Pipeline[http://docs.seattlerb.org/net-http-pipeline/Net/HTTP/Pipeline.html]
821
- # for further details.
822
- #
823
- # Only if <tt>net-http-pipeline</tt> was required before
824
- # <tt>net-http-persistent</tt> #pipeline will be present.
825
-
826
- def pipeline uri, requests, &block # :yields: responses
827
- connection = connection_for uri
828
-
829
- connection.pipeline requests, &block
830
- end
831
-
832
771
  ##
833
772
  # Sets this client's SSL private key
834
773
 
@@ -842,12 +781,12 @@ class Bundler::Persistent::Net::HTTP::Persistent
842
781
  alias key= private_key=
843
782
 
844
783
  ##
845
- # Sets the proxy server. The +proxy+ may be the URI of the proxy server,
784
+ # Sets the proxy server. The +proxy+ may be the Bundler::URI of the proxy server,
846
785
  # the symbol +:ENV+ which will read the proxy from the environment or nil to
847
786
  # disable use of a proxy. See #proxy_from_env for details on setting the
848
787
  # proxy from the environment.
849
788
  #
850
- # If the proxy URI is set after requests have been made, the next request
789
+ # If the proxy Bundler::URI is set after requests have been made, the next request
851
790
  # will shut-down and re-open all connections.
852
791
  #
853
792
  # The +no_proxy+ query parameter can be used to specify hosts which shouldn't
@@ -858,9 +797,9 @@ class Bundler::Persistent::Net::HTTP::Persistent
858
797
  def proxy= proxy
859
798
  @proxy_uri = case proxy
860
799
  when :ENV then proxy_from_env
861
- when URI::HTTP then proxy
800
+ when Bundler::URI::HTTP then proxy
862
801
  when nil then # ignore
863
- else raise ArgumentError, 'proxy must be :ENV or a URI::HTTP'
802
+ else raise ArgumentError, 'proxy must be :ENV or a Bundler::URI::HTTP'
864
803
  end
865
804
 
866
805
  @no_proxy.clear
@@ -885,13 +824,13 @@ class Bundler::Persistent::Net::HTTP::Persistent
885
824
  end
886
825
 
887
826
  ##
888
- # Creates a URI for an HTTP proxy server from ENV variables.
827
+ # Creates a Bundler::URI for an HTTP proxy server from ENV variables.
889
828
  #
890
829
  # If +HTTP_PROXY+ is set a proxy will be returned.
891
830
  #
892
- # If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the URI is given the
831
+ # If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the Bundler::URI is given the
893
832
  # indicated user and password unless HTTP_PROXY contains either of these in
894
- # the URI.
833
+ # the Bundler::URI.
895
834
  #
896
835
  # The +NO_PROXY+ ENV variable can be used to specify hosts which shouldn't
897
836
  # be reached via proxy; if set it should be a comma separated list of
@@ -907,7 +846,7 @@ class Bundler::Persistent::Net::HTTP::Persistent
907
846
 
908
847
  return nil if env_proxy.nil? or env_proxy.empty?
909
848
 
910
- uri = URI normalize_uri env_proxy
849
+ uri = Bundler::URI normalize_uri env_proxy
911
850
 
912
851
  env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
913
852
 
@@ -959,18 +898,17 @@ class Bundler::Persistent::Net::HTTP::Persistent
959
898
  # Finishes then restarts the Net::HTTP +connection+
960
899
 
961
900
  def reset connection
962
- Thread.current[@request_key].delete connection.object_id
963
- Thread.current[@timeout_key].delete connection.object_id
901
+ http = connection.http
964
902
 
965
903
  finish connection
966
904
 
967
- start connection
905
+ start http
968
906
  rescue Errno::ECONNREFUSED
969
- e = Error.new "connection refused: #{connection.address}:#{connection.port}"
907
+ e = Error.new "connection refused: #{http.address}:#{http.port}"
970
908
  e.set_backtrace $@
971
909
  raise e
972
910
  rescue Errno::EHOSTDOWN
973
- e = Error.new "host down: #{connection.address}:#{connection.port}"
911
+ e = Error.new "host down: #{http.address}:#{http.port}"
974
912
  e.set_backtrace $@
975
913
  raise e
976
914
  end
@@ -982,7 +920,7 @@ class Bundler::Persistent::Net::HTTP::Persistent
982
920
  # If a block is passed #request behaves like Net::HTTP#request (the body of
983
921
  # the response will not have been read).
984
922
  #
985
- # +req+ must be a Net::HTTPRequest subclass (see Net::HTTP for a list).
923
+ # +req+ must be a Net::HTTPGenericRequest subclass (see Net::HTTP for a list).
986
924
  #
987
925
  # If there is an error and the request is idempotent according to RFC 2616
988
926
  # it will be retried automatically.
@@ -991,52 +929,56 @@ class Bundler::Persistent::Net::HTTP::Persistent
991
929
  retried = false
992
930
  bad_response = false
993
931
 
994
- req = request_setup req || uri
932
+ uri = Bundler::URI uri
933
+ req = request_setup req || uri
934
+ response = nil
995
935
 
996
- connection = connection_for uri
997
- connection_id = connection.object_id
936
+ connection_for uri do |connection|
937
+ http = connection.http
998
938
 
999
- begin
1000
- Thread.current[@request_key][connection_id] += 1
1001
- response = connection.request req, &block
939
+ begin
940
+ connection.requests += 1
1002
941
 
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
942
+ response = http.request req, &block
943
+
944
+ if req.connection_close? or
945
+ (response.http_version <= '1.0' and
946
+ not response.connection_keep_alive?) or
947
+ response.connection_close? then
948
+ finish connection
949
+ end
950
+ rescue Net::HTTPBadResponse => e
951
+ message = error_message connection
1011
952
 
1012
- finish connection
953
+ finish connection
1013
954
 
1014
- raise Error, "too many bad responses #{message}" if
955
+ raise Error, "too many bad responses #{message}" if
1015
956
  bad_response or not can_retry? req
1016
957
 
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
958
+ bad_response = true
959
+ retry
960
+ rescue *RETRIED_EXCEPTIONS => e
961
+ request_failed e, req, connection if
962
+ retried or not can_retry? req
1022
963
 
1023
- reset connection
964
+ reset connection
1024
965
 
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
966
+ retried = true
967
+ retry
968
+ rescue Errno::EINVAL, Errno::ETIMEDOUT => e # not retried on ruby 2
969
+ request_failed e, req, connection if retried or not can_retry? req
1029
970
 
1030
- reset connection
971
+ reset connection
1031
972
 
1032
- retried = true
1033
- retry
1034
- rescue Exception => e
1035
- finish connection
973
+ retried = true
974
+ retry
975
+ rescue Exception => e
976
+ finish connection
1036
977
 
1037
- raise
1038
- ensure
1039
- Thread.current[@timeout_key][connection_id] = Time.now
978
+ raise
979
+ ensure
980
+ connection.last_use = Time.now
981
+ end
1040
982
  end
1041
983
 
1042
984
  @http_versions["#{uri.host}:#{uri.port}"] ||= response.http_version
@@ -1056,18 +998,17 @@ class Bundler::Persistent::Net::HTTP::Persistent
1056
998
 
1057
999
  finish connection
1058
1000
 
1059
-
1060
1001
  raise Error, message, exception.backtrace
1061
1002
  end
1062
1003
 
1063
1004
  ##
1064
- # Creates a GET request if +req_or_uri+ is a URI and adds headers to the
1005
+ # Creates a GET request if +req_or_uri+ is a Bundler::URI and adds headers to the
1065
1006
  # request.
1066
1007
  #
1067
1008
  # Returns the request.
1068
1009
 
1069
1010
  def request_setup req_or_uri # :nodoc:
1070
- req = if URI === req_or_uri then
1011
+ req = if Bundler::URI === req_or_uri then
1071
1012
  Net::HTTP::Get.new req_or_uri.request_uri
1072
1013
  else
1073
1014
  req_or_uri
@@ -1090,45 +1031,15 @@ class Bundler::Persistent::Net::HTTP::Persistent
1090
1031
  end
1091
1032
 
1092
1033
  ##
1093
- # Shuts down all connections for +thread+.
1034
+ # Shuts down all connections
1094
1035
  #
1095
- # Uses the current thread by default.
1036
+ # *NOTE*: Calling shutdown for can be dangerous!
1096
1037
  #
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.
1099
- #
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
1111
-
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!
1038
+ # If any thread is still using a connection it may cause an error! Call
1039
+ # #shutdown when you are completely done making requests!
1125
1040
 
1126
- def shutdown_in_all_threads
1127
- Thread.list.each do |thread|
1128
- shutdown thread
1129
- end
1130
-
1131
- nil
1041
+ def shutdown
1042
+ @pool.shutdown { |http| http.finish }
1132
1043
  end
1133
1044
 
1134
1045
  ##
@@ -1137,9 +1048,14 @@ class Bundler::Persistent::Net::HTTP::Persistent
1137
1048
  def ssl connection
1138
1049
  connection.use_ssl = true
1139
1050
 
1051
+ connection.ciphers = @ciphers if @ciphers
1052
+ connection.ssl_timeout = @ssl_timeout if @ssl_timeout
1140
1053
  connection.ssl_version = @ssl_version if @ssl_version
1054
+ connection.min_version = @min_version if @min_version
1055
+ connection.max_version = @max_version if @max_version
1141
1056
 
1142
- connection.verify_mode = @verify_mode
1057
+ connection.verify_depth = @verify_depth
1058
+ connection.verify_mode = @verify_mode
1143
1059
 
1144
1060
  if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
1145
1061
  not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
@@ -1168,8 +1084,10 @@ application:
1168
1084
  WARNING
1169
1085
  end
1170
1086
 
1171
- if @ca_file then
1172
- connection.ca_file = @ca_file
1087
+ connection.ca_file = @ca_file if @ca_file
1088
+ connection.ca_path = @ca_path if @ca_path
1089
+
1090
+ if @ca_file or @ca_path then
1173
1091
  connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
1174
1092
  connection.verify_callback = @verify_callback if @verify_callback
1175
1093
  end
@@ -1189,11 +1107,12 @@ application:
1189
1107
  end
1190
1108
 
1191
1109
  ##
1192
- # Finishes all connections that existed before the given SSL parameter
1193
- # +generation+.
1110
+ # SSL session lifetime
1194
1111
 
1195
- def ssl_cleanup generation # :nodoc:
1196
- cleanup generation, Thread.current, @ssl_generation_key
1112
+ def ssl_timeout= ssl_timeout
1113
+ @ssl_timeout = ssl_timeout
1114
+
1115
+ reconnect_ssl
1197
1116
  end
1198
1117
 
1199
1118
  ##
@@ -1203,7 +1122,34 @@ application:
1203
1122
  @ssl_version = ssl_version
1204
1123
 
1205
1124
  reconnect_ssl
1206
- end if RUBY_VERSION > '1.9'
1125
+ end
1126
+
1127
+ ##
1128
+ # Minimum SSL version to use
1129
+
1130
+ def min_version= min_version
1131
+ @min_version = min_version
1132
+
1133
+ reconnect_ssl
1134
+ end
1135
+
1136
+ ##
1137
+ # maximum SSL version to use
1138
+
1139
+ def max_version= max_version
1140
+ @max_version = max_version
1141
+
1142
+ reconnect_ssl
1143
+ end
1144
+
1145
+ ##
1146
+ # Sets the depth of SSL certificate verification
1147
+
1148
+ def verify_depth= verify_depth
1149
+ @verify_depth = verify_depth
1150
+
1151
+ reconnect_ssl
1152
+ end
1207
1153
 
1208
1154
  ##
1209
1155
  # Sets the HTTPS verify mode. Defaults to OpenSSL::SSL::VERIFY_PEER.
@@ -1229,5 +1175,6 @@ application:
1229
1175
 
1230
1176
  end
1231
1177
 
1232
- require 'bundler/vendor/net-http-persistent/lib/net/http/persistent/ssl_reuse'
1178
+ require_relative 'persistent/connection'
1179
+ require_relative 'persistent/pool'
1233
1180