bundler-clone 4.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (350) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5670 -0
  3. data/LICENSE.md +22 -0
  4. data/README.md +58 -0
  5. data/bundler.gemspec +46 -0
  6. data/exe/bundle +29 -0
  7. data/exe/bundler +4 -0
  8. data/lib/bundler/.document +1 -0
  9. data/lib/bundler/build_metadata.rb +44 -0
  10. data/lib/bundler/capistrano.rb +4 -0
  11. data/lib/bundler/checksum.rb +270 -0
  12. data/lib/bundler/ci_detector.rb +75 -0
  13. data/lib/bundler/cli/add.rb +62 -0
  14. data/lib/bundler/cli/binstubs.rb +57 -0
  15. data/lib/bundler/cli/cache.rb +32 -0
  16. data/lib/bundler/cli/check.rb +40 -0
  17. data/lib/bundler/cli/clean.rb +25 -0
  18. data/lib/bundler/cli/common.rb +161 -0
  19. data/lib/bundler/cli/config.rb +208 -0
  20. data/lib/bundler/cli/console.rb +47 -0
  21. data/lib/bundler/cli/doctor/diagnose.rb +167 -0
  22. data/lib/bundler/cli/doctor/ssl.rb +249 -0
  23. data/lib/bundler/cli/doctor.rb +33 -0
  24. data/lib/bundler/cli/exec.rb +114 -0
  25. data/lib/bundler/cli/fund.rb +36 -0
  26. data/lib/bundler/cli/gem.rb +493 -0
  27. data/lib/bundler/cli/info.rb +83 -0
  28. data/lib/bundler/cli/init.rb +51 -0
  29. data/lib/bundler/cli/install.rb +127 -0
  30. data/lib/bundler/cli/issue.rb +41 -0
  31. data/lib/bundler/cli/list.rb +97 -0
  32. data/lib/bundler/cli/lock.rb +94 -0
  33. data/lib/bundler/cli/open.rb +29 -0
  34. data/lib/bundler/cli/outdated.rb +337 -0
  35. data/lib/bundler/cli/platform.rb +48 -0
  36. data/lib/bundler/cli/plugin.rb +39 -0
  37. data/lib/bundler/cli/pristine.rb +64 -0
  38. data/lib/bundler/cli/remove.rb +17 -0
  39. data/lib/bundler/cli/show.rb +71 -0
  40. data/lib/bundler/cli/update.rb +125 -0
  41. data/lib/bundler/cli.rb +829 -0
  42. data/lib/bundler/compact_index_client/cache.rb +96 -0
  43. data/lib/bundler/compact_index_client/cache_file.rb +148 -0
  44. data/lib/bundler/compact_index_client/parser.rb +87 -0
  45. data/lib/bundler/compact_index_client/updater.rb +105 -0
  46. data/lib/bundler/compact_index_client.rb +92 -0
  47. data/lib/bundler/constants.rb +14 -0
  48. data/lib/bundler/current_ruby.rb +94 -0
  49. data/lib/bundler/definition.rb +1304 -0
  50. data/lib/bundler/dependency.rb +151 -0
  51. data/lib/bundler/deployment.rb +6 -0
  52. data/lib/bundler/deprecate.rb +44 -0
  53. data/lib/bundler/digest.rb +71 -0
  54. data/lib/bundler/dsl.rb +642 -0
  55. data/lib/bundler/endpoint_specification.rb +184 -0
  56. data/lib/bundler/env.rb +148 -0
  57. data/lib/bundler/environment_preserver.rb +69 -0
  58. data/lib/bundler/errors.rb +277 -0
  59. data/lib/bundler/feature_flag.rb +20 -0
  60. data/lib/bundler/fetcher/base.rb +55 -0
  61. data/lib/bundler/fetcher/compact_index.rb +133 -0
  62. data/lib/bundler/fetcher/dependency.rb +85 -0
  63. data/lib/bundler/fetcher/downloader.rb +116 -0
  64. data/lib/bundler/fetcher/gem_remote_fetcher.rb +24 -0
  65. data/lib/bundler/fetcher/index.rb +25 -0
  66. data/lib/bundler/fetcher.rb +365 -0
  67. data/lib/bundler/force_platform.rb +16 -0
  68. data/lib/bundler/friendly_errors.rb +127 -0
  69. data/lib/bundler/gem_helper.rb +237 -0
  70. data/lib/bundler/gem_tasks.rb +7 -0
  71. data/lib/bundler/gem_version_promoter.rb +147 -0
  72. data/lib/bundler/index.rb +203 -0
  73. data/lib/bundler/injector.rb +284 -0
  74. data/lib/bundler/inline.rb +106 -0
  75. data/lib/bundler/installer/gem_installer.rb +88 -0
  76. data/lib/bundler/installer/parallel_installer.rb +280 -0
  77. data/lib/bundler/installer/standalone.rb +113 -0
  78. data/lib/bundler/installer.rb +241 -0
  79. data/lib/bundler/lazy_specification.rb +270 -0
  80. data/lib/bundler/lockfile_generator.rb +119 -0
  81. data/lib/bundler/lockfile_parser.rb +328 -0
  82. data/lib/bundler/man/.document +1 -0
  83. data/lib/bundler/man/bundle-add.1 +79 -0
  84. data/lib/bundler/man/bundle-add.1.ronn +92 -0
  85. data/lib/bundler/man/bundle-binstubs.1 +30 -0
  86. data/lib/bundler/man/bundle-binstubs.1.ronn +42 -0
  87. data/lib/bundler/man/bundle-cache.1 +56 -0
  88. data/lib/bundler/man/bundle-cache.1.ronn +95 -0
  89. data/lib/bundler/man/bundle-check.1 +21 -0
  90. data/lib/bundler/man/bundle-check.1.ronn +26 -0
  91. data/lib/bundler/man/bundle-clean.1 +17 -0
  92. data/lib/bundler/man/bundle-clean.1.ronn +18 -0
  93. data/lib/bundler/man/bundle-config.1 +339 -0
  94. data/lib/bundler/man/bundle-config.1.ronn +455 -0
  95. data/lib/bundler/man/bundle-console.1 +33 -0
  96. data/lib/bundler/man/bundle-console.1.ronn +39 -0
  97. data/lib/bundler/man/bundle-doctor.1 +69 -0
  98. data/lib/bundler/man/bundle-doctor.1.ronn +77 -0
  99. data/lib/bundler/man/bundle-env.1 +9 -0
  100. data/lib/bundler/man/bundle-env.1.ronn +10 -0
  101. data/lib/bundler/man/bundle-exec.1 +104 -0
  102. data/lib/bundler/man/bundle-exec.1.ronn +150 -0
  103. data/lib/bundler/man/bundle-fund.1 +22 -0
  104. data/lib/bundler/man/bundle-fund.1.ronn +25 -0
  105. data/lib/bundler/man/bundle-gem.1 +107 -0
  106. data/lib/bundler/man/bundle-gem.1.ronn +150 -0
  107. data/lib/bundler/man/bundle-help.1 +9 -0
  108. data/lib/bundler/man/bundle-help.1.ronn +12 -0
  109. data/lib/bundler/man/bundle-info.1 +17 -0
  110. data/lib/bundler/man/bundle-info.1.ronn +21 -0
  111. data/lib/bundler/man/bundle-init.1 +20 -0
  112. data/lib/bundler/man/bundle-init.1.ronn +32 -0
  113. data/lib/bundler/man/bundle-install.1 +178 -0
  114. data/lib/bundler/man/bundle-install.1.ronn +314 -0
  115. data/lib/bundler/man/bundle-issue.1 +45 -0
  116. data/lib/bundler/man/bundle-issue.1.ronn +37 -0
  117. data/lib/bundler/man/bundle-licenses.1 +9 -0
  118. data/lib/bundler/man/bundle-licenses.1.ronn +10 -0
  119. data/lib/bundler/man/bundle-list.1 +40 -0
  120. data/lib/bundler/man/bundle-list.1.ronn +41 -0
  121. data/lib/bundler/man/bundle-lock.1 +75 -0
  122. data/lib/bundler/man/bundle-lock.1.ronn +115 -0
  123. data/lib/bundler/man/bundle-open.1 +32 -0
  124. data/lib/bundler/man/bundle-open.1.ronn +28 -0
  125. data/lib/bundler/man/bundle-outdated.1 +106 -0
  126. data/lib/bundler/man/bundle-outdated.1.ronn +117 -0
  127. data/lib/bundler/man/bundle-platform.1 +49 -0
  128. data/lib/bundler/man/bundle-platform.1.ronn +49 -0
  129. data/lib/bundler/man/bundle-plugin.1 +76 -0
  130. data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
  131. data/lib/bundler/man/bundle-pristine.1 +23 -0
  132. data/lib/bundler/man/bundle-pristine.1.ronn +34 -0
  133. data/lib/bundler/man/bundle-remove.1 +15 -0
  134. data/lib/bundler/man/bundle-remove.1.ronn +16 -0
  135. data/lib/bundler/man/bundle-show.1 +16 -0
  136. data/lib/bundler/man/bundle-show.1.ronn +21 -0
  137. data/lib/bundler/man/bundle-update.1 +284 -0
  138. data/lib/bundler/man/bundle-update.1.ronn +367 -0
  139. data/lib/bundler/man/bundle-version.1 +22 -0
  140. data/lib/bundler/man/bundle-version.1.ronn +24 -0
  141. data/lib/bundler/man/bundle.1 +93 -0
  142. data/lib/bundler/man/bundle.1.ronn +107 -0
  143. data/lib/bundler/man/gemfile.5 +503 -0
  144. data/lib/bundler/man/gemfile.5.ronn +586 -0
  145. data/lib/bundler/man/index.txt +31 -0
  146. data/lib/bundler/match_metadata.rb +30 -0
  147. data/lib/bundler/match_platform.rb +42 -0
  148. data/lib/bundler/match_remote_metadata.rb +29 -0
  149. data/lib/bundler/materialization.rb +59 -0
  150. data/lib/bundler/mirror.rb +221 -0
  151. data/lib/bundler/plugin/api/source.rb +330 -0
  152. data/lib/bundler/plugin/api.rb +81 -0
  153. data/lib/bundler/plugin/dsl.rb +53 -0
  154. data/lib/bundler/plugin/events.rb +85 -0
  155. data/lib/bundler/plugin/index.rb +203 -0
  156. data/lib/bundler/plugin/installer/git.rb +34 -0
  157. data/lib/bundler/plugin/installer/path.rb +26 -0
  158. data/lib/bundler/plugin/installer/rubygems.rb +19 -0
  159. data/lib/bundler/plugin/installer.rb +123 -0
  160. data/lib/bundler/plugin/source_list.rb +31 -0
  161. data/lib/bundler/plugin/unloaded_source.rb +25 -0
  162. data/lib/bundler/plugin.rb +387 -0
  163. data/lib/bundler/process_lock.rb +20 -0
  164. data/lib/bundler/remote_specification.rb +126 -0
  165. data/lib/bundler/resolver/base.rb +127 -0
  166. data/lib/bundler/resolver/candidate.rb +85 -0
  167. data/lib/bundler/resolver/incompatibility.rb +15 -0
  168. data/lib/bundler/resolver/package.rb +95 -0
  169. data/lib/bundler/resolver/root.rb +25 -0
  170. data/lib/bundler/resolver/spec_group.rb +74 -0
  171. data/lib/bundler/resolver/strategy.rb +43 -0
  172. data/lib/bundler/resolver.rb +603 -0
  173. data/lib/bundler/retry.rb +92 -0
  174. data/lib/bundler/ruby_dsl.rb +67 -0
  175. data/lib/bundler/ruby_version.rb +135 -0
  176. data/lib/bundler/rubygems_ext.rb +503 -0
  177. data/lib/bundler/rubygems_gem_installer.rb +206 -0
  178. data/lib/bundler/rubygems_integration.rb +456 -0
  179. data/lib/bundler/runtime.rb +331 -0
  180. data/lib/bundler/safe_marshal.rb +31 -0
  181. data/lib/bundler/self_manager.rb +197 -0
  182. data/lib/bundler/settings/validator.rb +86 -0
  183. data/lib/bundler/settings.rb +585 -0
  184. data/lib/bundler/setup.rb +39 -0
  185. data/lib/bundler/shared_helpers.rb +392 -0
  186. data/lib/bundler/source/gemspec.rb +19 -0
  187. data/lib/bundler/source/git/git_proxy.rb +509 -0
  188. data/lib/bundler/source/git.rb +451 -0
  189. data/lib/bundler/source/metadata.rb +67 -0
  190. data/lib/bundler/source/path/installer.rb +53 -0
  191. data/lib/bundler/source/path.rb +256 -0
  192. data/lib/bundler/source/rubygems/remote.rb +86 -0
  193. data/lib/bundler/source/rubygems.rb +606 -0
  194. data/lib/bundler/source/rubygems_aggregate.rb +71 -0
  195. data/lib/bundler/source.rb +120 -0
  196. data/lib/bundler/source_list.rb +240 -0
  197. data/lib/bundler/source_map.rb +72 -0
  198. data/lib/bundler/spec_set.rb +390 -0
  199. data/lib/bundler/stub_specification.rb +147 -0
  200. data/lib/bundler/templates/.document +1 -0
  201. data/lib/bundler/templates/Executable +16 -0
  202. data/lib/bundler/templates/Executable.standalone +14 -0
  203. data/lib/bundler/templates/Gemfile +5 -0
  204. data/lib/bundler/templates/newgem/CHANGELOG.md.tt +5 -0
  205. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +10 -0
  206. data/lib/bundler/templates/newgem/Cargo.toml.tt +13 -0
  207. data/lib/bundler/templates/newgem/Gemfile.tt +24 -0
  208. data/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
  209. data/lib/bundler/templates/newgem/README.md.tt +49 -0
  210. data/lib/bundler/templates/newgem/Rakefile.tt +72 -0
  211. data/lib/bundler/templates/newgem/bin/console.tt +11 -0
  212. data/lib/bundler/templates/newgem/bin/setup.tt +8 -0
  213. data/lib/bundler/templates/newgem/circleci/config.yml.tt +37 -0
  214. data/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
  215. data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +22 -0
  216. data/lib/bundler/templates/newgem/ext/newgem/build.rs.tt +5 -0
  217. data/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
  218. data/lib/bundler/templates/newgem/ext/newgem/extconf-go.rb.tt +11 -0
  219. data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  220. data/lib/bundler/templates/newgem/ext/newgem/go.mod.tt +5 -0
  221. data/lib/bundler/templates/newgem/ext/newgem/newgem-go.c.tt +2 -0
  222. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  223. data/lib/bundler/templates/newgem/ext/newgem/newgem.go.tt +31 -0
  224. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  225. data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +23 -0
  226. data/lib/bundler/templates/newgem/github/workflows/build-gems.yml.tt +69 -0
  227. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +48 -0
  228. data/lib/bundler/templates/newgem/gitignore.tt +23 -0
  229. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +27 -0
  230. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +9 -0
  231. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +15 -0
  232. data/lib/bundler/templates/newgem/newgem.gemspec.tt +58 -0
  233. data/lib/bundler/templates/newgem/rspec.tt +3 -0
  234. data/lib/bundler/templates/newgem/rubocop.yml.tt +8 -0
  235. data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
  236. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +19 -0
  237. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +15 -0
  238. data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
  239. data/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt +6 -0
  240. data/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt +19 -0
  241. data/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt +15 -0
  242. data/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt +6 -0
  243. data/lib/bundler/ui/rg_proxy.rb +19 -0
  244. data/lib/bundler/ui/shell.rb +191 -0
  245. data/lib/bundler/ui/silent.rb +96 -0
  246. data/lib/bundler/ui.rb +9 -0
  247. data/lib/bundler/uri_credentials_filter.rb +43 -0
  248. data/lib/bundler/uri_normalizer.rb +23 -0
  249. data/lib/bundler/vendor/.document +1 -0
  250. data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
  251. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +227 -0
  252. data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +3 -0
  253. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +56 -0
  254. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +230 -0
  255. data/lib/bundler/vendor/fileutils/COPYING +56 -0
  256. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +2701 -0
  257. data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
  258. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +41 -0
  259. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +65 -0
  260. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +80 -0
  261. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1153 -0
  262. data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  263. data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  264. data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +169 -0
  265. data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  266. data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
  267. data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  268. data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  269. data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  270. data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  271. data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +61 -0
  272. data/lib/bundler/vendor/pub_grub/lib/pub_grub/strategy.rb +42 -0
  273. data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  274. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  275. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
  276. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +423 -0
  277. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +236 -0
  278. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  279. data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  280. data/lib/bundler/vendor/securerandom/COPYING +56 -0
  281. data/lib/bundler/vendor/securerandom/lib/securerandom.rb +102 -0
  282. data/lib/bundler/vendor/thor/LICENSE.md +20 -0
  283. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  284. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +61 -0
  285. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +108 -0
  286. data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +143 -0
  287. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +407 -0
  288. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +130 -0
  289. data/lib/bundler/vendor/thor/lib/thor/actions.rb +340 -0
  290. data/lib/bundler/vendor/thor/lib/thor/base.rb +825 -0
  291. data/lib/bundler/vendor/thor/lib/thor/command.rb +151 -0
  292. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +107 -0
  293. data/lib/bundler/vendor/thor/lib/thor/error.rb +106 -0
  294. data/lib/bundler/vendor/thor/lib/thor/group.rb +292 -0
  295. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +178 -0
  296. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +37 -0
  297. data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  298. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
  299. data/lib/bundler/vendor/thor/lib/thor/nested_context.rb +29 -0
  300. data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +86 -0
  301. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +195 -0
  302. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +178 -0
  303. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +294 -0
  304. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
  305. data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +72 -0
  306. data/lib/bundler/vendor/thor/lib/thor/runner.rb +335 -0
  307. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +384 -0
  308. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +112 -0
  309. data/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
  310. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +81 -0
  311. data/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +118 -0
  312. data/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
  313. data/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
  314. data/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
  315. data/lib/bundler/vendor/thor/lib/thor/util.rb +285 -0
  316. data/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
  317. data/lib/bundler/vendor/thor/lib/thor.rb +674 -0
  318. data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  319. data/lib/bundler/vendor/tsort/lib/tsort.rb +455 -0
  320. data/lib/bundler/vendor/uri/COPYING +56 -0
  321. data/lib/bundler/vendor/uri/lib/uri/common.rb +922 -0
  322. data/lib/bundler/vendor/uri/lib/uri/file.rb +100 -0
  323. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +267 -0
  324. data/lib/bundler/vendor/uri/lib/uri/generic.rb +1592 -0
  325. data/lib/bundler/vendor/uri/lib/uri/http.rb +137 -0
  326. data/lib/bundler/vendor/uri/lib/uri/https.rb +23 -0
  327. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +261 -0
  328. data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +22 -0
  329. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +293 -0
  330. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +547 -0
  331. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +206 -0
  332. data/lib/bundler/vendor/uri/lib/uri/version.rb +6 -0
  333. data/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
  334. data/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
  335. data/lib/bundler/vendor/uri/lib/uri.rb +104 -0
  336. data/lib/bundler/vendored_fileutils.rb +4 -0
  337. data/lib/bundler/vendored_net_http.rb +23 -0
  338. data/lib/bundler/vendored_persistent.rb +11 -0
  339. data/lib/bundler/vendored_pub_grub.rb +4 -0
  340. data/lib/bundler/vendored_securerandom.rb +12 -0
  341. data/lib/bundler/vendored_thor.rb +8 -0
  342. data/lib/bundler/vendored_timeout.rb +12 -0
  343. data/lib/bundler/vendored_tsort.rb +4 -0
  344. data/lib/bundler/vendored_uri.rb +21 -0
  345. data/lib/bundler/version.rb +21 -0
  346. data/lib/bundler/vlad.rb +4 -0
  347. data/lib/bundler/worker.rb +125 -0
  348. data/lib/bundler/yaml_serializer.rb +98 -0
  349. data/lib/bundler.rb +691 -0
  350. metadata +409 -0
@@ -0,0 +1,1153 @@
1
+ require_relative '../../../../../vendored_net_http'
2
+ require_relative '../../../../../vendored_uri'
3
+ begin
4
+ require 'cgi/escape'
5
+ rescue LoadError
6
+ require 'cgi/util' # for escaping
7
+ end
8
+ require_relative '../../../../connection_pool/lib/connection_pool'
9
+
10
+ autoload :OpenSSL, 'openssl'
11
+
12
+ ##
13
+ # Persistent connections for Gem::Net::HTTP
14
+ #
15
+ # Gem::Net::HTTP::Persistent maintains persistent connections across all the
16
+ # servers you wish to talk to. For each host:port you communicate with a
17
+ # single persistent connection is created.
18
+ #
19
+ # Connections will be shared across threads through a connection pool to
20
+ # increase reuse of connections.
21
+ #
22
+ # You can shut down any remaining HTTP connections when done by calling
23
+ # #shutdown.
24
+ #
25
+ # Example:
26
+ #
27
+ # require 'bundler/vendor/net-http-persistent/lib/net/http/persistent'
28
+ #
29
+ # uri = Gem::URI 'http://example.com/awesome/web/service'
30
+ #
31
+ # http = Gem::Net::HTTP::Persistent.new
32
+ #
33
+ # # perform a GET
34
+ # response = http.request uri
35
+ #
36
+ # # or
37
+ #
38
+ # get = Gem::Net::HTTP::Get.new uri.request_uri
39
+ # response = http.request get
40
+ #
41
+ # # create a POST
42
+ # post_uri = uri + 'create'
43
+ # post = Gem::Net::HTTP::Post.new post_uri.path
44
+ # post.set_form_data 'some' => 'cool data'
45
+ #
46
+ # # perform the POST, the Gem::URI is always required
47
+ # response http.request post_uri, post
48
+ #
49
+ # ⚠ Note that for GET, HEAD and other requests that do not have a body,
50
+ # it uses Gem::URI#request_uri as default to send query params
51
+ #
52
+ # == TLS/SSL
53
+ #
54
+ # TLS connections are automatically created depending upon the scheme of the
55
+ # Gem::URI. TLS connections are automatically verified against the default
56
+ # certificate store for your computer. You can override this by changing
57
+ # verify_mode or by specifying an alternate cert_store.
58
+ #
59
+ # Here are the TLS settings, see the individual methods for documentation:
60
+ #
61
+ # #certificate :: This client's certificate
62
+ # #ca_file :: The certificate-authorities
63
+ # #ca_path :: Directory with certificate-authorities
64
+ # #cert_store :: An SSL certificate store
65
+ # #ciphers :: List of SSl ciphers allowed
66
+ # #extra_chain_cert :: Extra certificates to be added to the certificate chain
67
+ # #private_key :: The client's SSL private key
68
+ # #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new
69
+ # connection
70
+ # #ssl_timeout :: Session lifetime
71
+ # #ssl_version :: Which specific SSL version to use
72
+ # #verify_callback :: For server certificate verification
73
+ # #verify_depth :: Depth of certificate verification
74
+ # #verify_mode :: How connections should be verified
75
+ # #verify_hostname :: Use hostname verification for server certificate
76
+ # during the handshake
77
+ #
78
+ # == Proxies
79
+ #
80
+ # A proxy can be set through #proxy= or at initialization time by providing a
81
+ # second argument to ::new. The proxy may be the Gem::URI of the proxy server or
82
+ # <code>:ENV</code> which will consult environment variables.
83
+ #
84
+ # See #proxy= and #proxy_from_env for details.
85
+ #
86
+ # == Headers
87
+ #
88
+ # Headers may be specified for use in every request. #headers are appended to
89
+ # any headers on the request. #override_headers replace existing headers on
90
+ # the request.
91
+ #
92
+ # The difference between the two can be seen in setting the User-Agent. Using
93
+ # <code>http.headers['User-Agent'] = 'MyUserAgent'</code> will send "Ruby,
94
+ # MyUserAgent" while <code>http.override_headers['User-Agent'] =
95
+ # 'MyUserAgent'</code> will send "MyUserAgent".
96
+ #
97
+ # == Tuning
98
+ #
99
+ # === Segregation
100
+ #
101
+ # Each Gem::Net::HTTP::Persistent instance has its own pool of connections. There
102
+ # is no sharing with other instances (as was true in earlier versions).
103
+ #
104
+ # === Idle Timeout
105
+ #
106
+ # If a connection hasn't been used for this number of seconds it will
107
+ # automatically be reset upon the next use to avoid attempting to send to a
108
+ # closed connection. The default value is 5 seconds. nil means no timeout.
109
+ # Set through #idle_timeout.
110
+ #
111
+ # Reducing this value may help avoid the "too many connection resets" error
112
+ # when sending non-idempotent requests while increasing this value will cause
113
+ # fewer round-trips.
114
+ #
115
+ # === Read Timeout
116
+ #
117
+ # The amount of time allowed between reading two chunks from the socket. Set
118
+ # through #read_timeout
119
+ #
120
+ # === Max Requests
121
+ #
122
+ # The number of requests that should be made before opening a new connection.
123
+ # Typically many keep-alive capable servers tune this to 100 or less, so the
124
+ # 101st request will fail with ECONNRESET. If unset (default), this value has
125
+ # no effect, if set, connections will be reset on the request after
126
+ # max_requests.
127
+ #
128
+ # === Open Timeout
129
+ #
130
+ # The amount of time to wait for a connection to be opened. Set through
131
+ # #open_timeout.
132
+ #
133
+ # === Socket Options
134
+ #
135
+ # Socket options may be set on newly-created connections. See #socket_options
136
+ # for details.
137
+ #
138
+ # === Connection Termination
139
+ #
140
+ # If you are done using the Gem::Net::HTTP::Persistent instance you may shut down
141
+ # all the connections in the current thread with #shutdown. This is not
142
+ # recommended for normal use, it should only be used when it will be several
143
+ # minutes before you make another HTTP request.
144
+ #
145
+ # If you are using multiple threads, call #shutdown in each thread when the
146
+ # thread is done making requests. If you don't call shutdown, that's OK.
147
+ # Ruby will automatically garbage collect and shutdown your HTTP connections
148
+ # when the thread terminates.
149
+
150
+ class Gem::Net::HTTP::Persistent
151
+
152
+ ##
153
+ # The beginning of Time
154
+
155
+ EPOCH = Time.at 0 # :nodoc:
156
+
157
+ ##
158
+ # Is OpenSSL available? This test works with autoload
159
+
160
+ HAVE_OPENSSL = defined? OpenSSL::SSL # :nodoc:
161
+
162
+ ##
163
+ # The default connection pool size is 1/4 the allowed open files
164
+ # (<code>ulimit -n</code>) or 256 if your OS does not support file handle
165
+ # limits (typically windows).
166
+
167
+ if Process.const_defined? :RLIMIT_NOFILE
168
+ open_file_limits = Process.getrlimit(Process::RLIMIT_NOFILE)
169
+
170
+ # Under JRuby on Windows Process responds to `getrlimit` but returns something that does not match docs
171
+ if open_file_limits.respond_to?(:first)
172
+ DEFAULT_POOL_SIZE = open_file_limits.first / 4
173
+ else
174
+ DEFAULT_POOL_SIZE = 256
175
+ end
176
+ else
177
+ DEFAULT_POOL_SIZE = 256
178
+ end
179
+
180
+ ##
181
+ # The version of Gem::Net::HTTP::Persistent you are using
182
+
183
+ VERSION = '4.0.6'
184
+
185
+ ##
186
+ # Error class for errors raised by Gem::Net::HTTP::Persistent. Various
187
+ # SystemCallErrors are re-raised with a human-readable message under this
188
+ # class.
189
+
190
+ class Error < StandardError; end
191
+
192
+ ##
193
+ # Use this method to detect the idle timeout of the host at +uri+. The
194
+ # value returned can be used to configure #idle_timeout. +max+ controls the
195
+ # maximum idle timeout to detect.
196
+ #
197
+ # After
198
+ #
199
+ # Idle timeout detection is performed by creating a connection then
200
+ # performing a HEAD request in a loop until the connection terminates
201
+ # waiting one additional second per loop.
202
+ #
203
+ # NOTE: This may not work on ruby > 1.9.
204
+
205
+ def self.detect_idle_timeout uri, max = 10
206
+ uri = Gem::URI uri unless Gem::URI::Generic === uri
207
+ uri += '/'
208
+
209
+ req = Gem::Net::HTTP::Head.new uri.request_uri
210
+
211
+ http = new 'net-http-persistent detect_idle_timeout'
212
+
213
+ http.connection_for uri do |connection|
214
+ sleep_time = 0
215
+
216
+ http = connection.http
217
+
218
+ loop do
219
+ response = http.request req
220
+
221
+ $stderr.puts "HEAD #{uri} => #{response.code}" if $DEBUG
222
+
223
+ unless Gem::Net::HTTPOK === response then
224
+ raise Error, "bad response code #{response.code} detecting idle timeout"
225
+ end
226
+
227
+ break if sleep_time >= max
228
+
229
+ sleep_time += 1
230
+
231
+ $stderr.puts "sleeping #{sleep_time}" if $DEBUG
232
+ sleep sleep_time
233
+ end
234
+ end
235
+ rescue
236
+ # ignore StandardErrors, we've probably found the idle timeout.
237
+ ensure
238
+ return sleep_time unless $!
239
+ end
240
+
241
+ ##
242
+ # This client's OpenSSL::X509::Certificate
243
+
244
+ attr_reader :certificate
245
+
246
+ ##
247
+ # For Gem::Net::HTTP parity
248
+
249
+ alias cert certificate
250
+
251
+ ##
252
+ # An SSL certificate authority. Setting this will set verify_mode to
253
+ # VERIFY_PEER.
254
+
255
+ attr_reader :ca_file
256
+
257
+ ##
258
+ # A directory of SSL certificates to be used as certificate authorities.
259
+ # Setting this will set verify_mode to VERIFY_PEER.
260
+
261
+ attr_reader :ca_path
262
+
263
+ ##
264
+ # An SSL certificate store. Setting this will override the default
265
+ # certificate store. See verify_mode for more information.
266
+
267
+ attr_reader :cert_store
268
+
269
+ ##
270
+ # The ciphers allowed for SSL connections
271
+
272
+ attr_reader :ciphers
273
+
274
+ ##
275
+ # Extra certificates to be added to the certificate chain
276
+
277
+ attr_reader :extra_chain_cert
278
+
279
+ ##
280
+ # Sends debug_output to this IO via Gem::Net::HTTP#set_debug_output.
281
+ #
282
+ # Never use this method in production code, it causes a serious security
283
+ # hole.
284
+
285
+ attr_accessor :debug_output
286
+
287
+ ##
288
+ # Current connection generation
289
+
290
+ attr_reader :generation # :nodoc:
291
+
292
+ ##
293
+ # Headers that are added to every request using Gem::Net::HTTP#add_field
294
+
295
+ attr_reader :headers
296
+
297
+ ##
298
+ # Maps host:port to an HTTP version. This allows us to enable version
299
+ # specific features.
300
+
301
+ attr_reader :http_versions
302
+
303
+ ##
304
+ # Maximum time an unused connection can remain idle before being
305
+ # automatically closed.
306
+
307
+ attr_accessor :idle_timeout
308
+
309
+ ##
310
+ # Maximum number of requests on a connection before it is considered expired
311
+ # and automatically closed.
312
+
313
+ attr_accessor :max_requests
314
+
315
+ ##
316
+ # Number of retries to perform if a request fails.
317
+ #
318
+ # See also #max_retries=, Gem::Net::HTTP#max_retries=.
319
+
320
+ attr_reader :max_retries
321
+
322
+ ##
323
+ # The value sent in the Keep-Alive header. Defaults to 30. Not needed for
324
+ # HTTP/1.1 servers.
325
+ #
326
+ # This may not work correctly for HTTP/1.0 servers
327
+ #
328
+ # This method may be removed in a future version as RFC 2616 does not
329
+ # require this header.
330
+
331
+ attr_accessor :keep_alive
332
+
333
+ ##
334
+ # The name for this collection of persistent connections.
335
+
336
+ attr_reader :name
337
+
338
+ ##
339
+ # Seconds to wait until a connection is opened. See Gem::Net::HTTP#open_timeout
340
+
341
+ attr_accessor :open_timeout
342
+
343
+ ##
344
+ # Headers that are added to every request using Gem::Net::HTTP#[]=
345
+
346
+ attr_reader :override_headers
347
+
348
+ ##
349
+ # This client's SSL private key
350
+
351
+ attr_reader :private_key
352
+
353
+ ##
354
+ # For Gem::Net::HTTP parity
355
+
356
+ alias key private_key
357
+
358
+ ##
359
+ # The URL through which requests will be proxied
360
+
361
+ attr_reader :proxy_uri
362
+
363
+ ##
364
+ # List of host suffixes which will not be proxied
365
+
366
+ attr_reader :no_proxy
367
+
368
+ ##
369
+ # Test-only accessor for the connection pool
370
+
371
+ attr_reader :pool # :nodoc:
372
+
373
+ ##
374
+ # Seconds to wait until reading one block. See Gem::Net::HTTP#read_timeout
375
+
376
+ attr_accessor :read_timeout
377
+
378
+ ##
379
+ # Seconds to wait until writing one block. See Gem::Net::HTTP#write_timeout
380
+
381
+ attr_accessor :write_timeout
382
+
383
+ ##
384
+ # By default SSL sessions are reused to avoid extra SSL handshakes. Set
385
+ # this to false if you have problems communicating with an HTTPS server
386
+ # like:
387
+ #
388
+ # SSL_connect [...] read finished A: unexpected message (OpenSSL::SSL::SSLError)
389
+
390
+ attr_accessor :reuse_ssl_sessions
391
+
392
+ ##
393
+ # An array of options for Socket#setsockopt.
394
+ #
395
+ # By default the TCP_NODELAY option is set on sockets.
396
+ #
397
+ # To set additional options append them to this array:
398
+ #
399
+ # http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
400
+
401
+ attr_reader :socket_options
402
+
403
+ ##
404
+ # Current SSL connection generation
405
+
406
+ attr_reader :ssl_generation # :nodoc:
407
+
408
+ ##
409
+ # SSL session lifetime
410
+
411
+ attr_reader :ssl_timeout
412
+
413
+ ##
414
+ # SSL version to use.
415
+ #
416
+ # By default, the version will be negotiated automatically between client
417
+ # and server. Ruby 1.9 and newer only. Deprecated since Ruby 2.5.
418
+
419
+ attr_reader :ssl_version
420
+
421
+ ##
422
+ # Minimum SSL version to use, e.g. :TLS1_1
423
+ #
424
+ # By default, the version will be negotiated automatically between client
425
+ # and server. Ruby 2.5 and newer only.
426
+
427
+ attr_reader :min_version
428
+
429
+ ##
430
+ # Maximum SSL version to use, e.g. :TLS1_2
431
+ #
432
+ # By default, the version will be negotiated automatically between client
433
+ # and server. Ruby 2.5 and newer only.
434
+
435
+ attr_reader :max_version
436
+
437
+ ##
438
+ # Where this instance's last-use times live in the thread local variables
439
+
440
+ attr_reader :timeout_key # :nodoc:
441
+
442
+ ##
443
+ # SSL verification callback. Used when ca_file or ca_path is set.
444
+
445
+ attr_reader :verify_callback
446
+
447
+ ##
448
+ # Sets the depth of SSL certificate verification
449
+
450
+ attr_reader :verify_depth
451
+
452
+ ##
453
+ # HTTPS verify mode. Defaults to OpenSSL::SSL::VERIFY_PEER which verifies
454
+ # the server certificate.
455
+ #
456
+ # If no ca_file, ca_path or cert_store is set the default system certificate
457
+ # store is used.
458
+ #
459
+ # You can use +verify_mode+ to override any default values.
460
+
461
+ attr_reader :verify_mode
462
+
463
+ ##
464
+ # HTTPS verify_hostname.
465
+ #
466
+ # If a client sets this to true and enables SNI with SSLSocket#hostname=,
467
+ # the hostname verification on the server certificate is performed
468
+ # automatically during the handshake using
469
+ # OpenSSL::SSL.verify_certificate_identity().
470
+ #
471
+ # You can set +verify_hostname+ as true to use hostname verification
472
+ # during the handshake.
473
+ #
474
+ # NOTE: This works with Ruby > 3.0.
475
+
476
+ attr_reader :verify_hostname
477
+
478
+ ##
479
+ # Creates a new Gem::Net::HTTP::Persistent.
480
+ #
481
+ # Set a +name+ for fun. Your library name should be good enough, but this
482
+ # otherwise has no purpose.
483
+ #
484
+ # +proxy+ may be set to a Gem::URI::HTTP or :ENV to pick up proxy options from
485
+ # the environment. See proxy_from_env for details.
486
+ #
487
+ # In order to use a Gem::URI for the proxy you may need to do some extra work
488
+ # beyond Gem::URI parsing if the proxy requires a password:
489
+ #
490
+ # proxy = Gem::URI 'http://proxy.example'
491
+ # proxy.user = 'AzureDiamond'
492
+ # proxy.password = 'hunter2'
493
+ #
494
+ # Set +pool_size+ to limit the maximum number of connections allowed.
495
+ # Defaults to 1/4 the number of allowed file handles or 256 if your OS does
496
+ # not support a limit on allowed file handles. You can have no more than
497
+ # this many threads with active HTTP transactions.
498
+
499
+ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
500
+ @name = name
501
+
502
+ @debug_output = nil
503
+ @proxy_uri = nil
504
+ @no_proxy = []
505
+ @headers = {}
506
+ @override_headers = {}
507
+ @http_versions = {}
508
+ @keep_alive = 30
509
+ @open_timeout = nil
510
+ @read_timeout = nil
511
+ @write_timeout = nil
512
+ @idle_timeout = 5
513
+ @max_requests = nil
514
+ @max_retries = 1
515
+ @socket_options = []
516
+ @ssl_generation = 0 # incremented when SSL session variables change
517
+
518
+ @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
519
+ Socket.const_defined? :TCP_NODELAY
520
+
521
+ @pool = Gem::Net::HTTP::Persistent::Pool.new size: pool_size do |http_args|
522
+ Gem::Net::HTTP::Persistent::Connection.new Gem::Net::HTTP, http_args, @ssl_generation
523
+ end
524
+
525
+ @certificate = nil
526
+ @ca_file = nil
527
+ @ca_path = nil
528
+ @ciphers = nil
529
+ @private_key = nil
530
+ @ssl_timeout = nil
531
+ @ssl_version = nil
532
+ @min_version = nil
533
+ @max_version = nil
534
+ @verify_callback = nil
535
+ @verify_depth = nil
536
+ @verify_mode = nil
537
+ @verify_hostname = nil
538
+ @cert_store = nil
539
+
540
+ @generation = 0 # incremented when proxy Gem::URI changes
541
+
542
+ if HAVE_OPENSSL then
543
+ @verify_mode = OpenSSL::SSL::VERIFY_PEER
544
+ @reuse_ssl_sessions = OpenSSL::SSL.const_defined? :Session
545
+ end
546
+
547
+ self.proxy = proxy if proxy
548
+ end
549
+
550
+ ##
551
+ # Sets this client's OpenSSL::X509::Certificate
552
+
553
+ def certificate= certificate
554
+ @certificate = certificate
555
+
556
+ reconnect_ssl
557
+ end
558
+
559
+ # For Gem::Net::HTTP parity
560
+ alias cert= certificate=
561
+
562
+ ##
563
+ # Sets the SSL certificate authority file.
564
+
565
+ def ca_file= file
566
+ @ca_file = file
567
+
568
+ reconnect_ssl
569
+ end
570
+
571
+ ##
572
+ # Sets the SSL certificate authority path.
573
+
574
+ def ca_path= path
575
+ @ca_path = path
576
+
577
+ reconnect_ssl
578
+ end
579
+
580
+ ##
581
+ # Overrides the default SSL certificate store used for verifying
582
+ # connections.
583
+
584
+ def cert_store= store
585
+ @cert_store = store
586
+
587
+ reconnect_ssl
588
+ end
589
+
590
+ ##
591
+ # The ciphers allowed for SSL connections
592
+
593
+ def ciphers= ciphers
594
+ @ciphers = ciphers
595
+
596
+ reconnect_ssl
597
+ end
598
+
599
+ if Gem::Net::HTTP.method_defined?(:extra_chain_cert=)
600
+ ##
601
+ # Extra certificates to be added to the certificate chain.
602
+ # It is only supported starting from Gem::Net::HTTP version 0.1.1
603
+ def extra_chain_cert= extra_chain_cert
604
+ @extra_chain_cert = extra_chain_cert
605
+
606
+ reconnect_ssl
607
+ end
608
+ else
609
+ def extra_chain_cert= _extra_chain_cert
610
+ raise "extra_chain_cert= is not supported by this version of Gem::Net::HTTP"
611
+ end
612
+ end
613
+
614
+ ##
615
+ # Creates a new connection for +uri+
616
+
617
+ def connection_for uri
618
+ use_ssl = uri.scheme.downcase == 'https'
619
+
620
+ net_http_args = [uri.hostname, uri.port]
621
+
622
+ # I'm unsure if uri.host or uri.hostname should be checked against
623
+ # the proxy bypass list.
624
+ if @proxy_uri and not proxy_bypass? uri.host, uri.port then
625
+ net_http_args.concat @proxy_args
626
+ else
627
+ net_http_args.concat [nil, nil, nil, nil]
628
+ end
629
+
630
+ connection = @pool.checkout net_http_args
631
+
632
+ begin
633
+ http = connection.http
634
+
635
+ connection.ressl @ssl_generation if
636
+ connection.ssl_generation != @ssl_generation
637
+
638
+ if not http.started? then
639
+ ssl http if use_ssl
640
+ start http
641
+ elsif expired? connection then
642
+ reset connection
643
+ end
644
+
645
+ http.keep_alive_timeout = @idle_timeout if @idle_timeout
646
+ http.max_retries = @max_retries if http.respond_to?(:max_retries=)
647
+ http.read_timeout = @read_timeout if @read_timeout
648
+ http.write_timeout = @write_timeout if
649
+ @write_timeout && http.respond_to?(:write_timeout=)
650
+
651
+ return yield connection
652
+ rescue Errno::ECONNREFUSED
653
+ if http.proxy?
654
+ address = http.proxy_address
655
+ port = http.proxy_port
656
+ else
657
+ address = http.address
658
+ port = http.port
659
+ end
660
+
661
+ raise Error, "connection refused: #{address}:#{port}"
662
+ rescue Errno::EHOSTDOWN
663
+ if http.proxy?
664
+ address = http.proxy_address
665
+ port = http.proxy_port
666
+ else
667
+ address = http.address
668
+ port = http.port
669
+ end
670
+
671
+ raise Error, "host down: #{address}:#{port}"
672
+ ensure
673
+ @pool.checkin net_http_args
674
+ end
675
+ end
676
+
677
+ ##
678
+ # CGI::escape wrapper
679
+
680
+ def escape str
681
+ CGI.escape str if str
682
+ end
683
+
684
+ ##
685
+ # CGI::unescape wrapper
686
+
687
+ def unescape str
688
+ CGI.unescape str if str
689
+ end
690
+
691
+
692
+ ##
693
+ # Returns true if the connection should be reset due to an idle timeout, or
694
+ # maximum request count, false otherwise.
695
+
696
+ def expired? connection
697
+ return true if @max_requests && connection.requests >= @max_requests
698
+ return false unless @idle_timeout
699
+ return true if @idle_timeout.zero?
700
+
701
+ Time.now - connection.last_use > @idle_timeout
702
+ end
703
+
704
+ ##
705
+ # Starts the Gem::Net::HTTP +connection+
706
+
707
+ def start http
708
+ http.set_debug_output @debug_output if @debug_output
709
+ http.open_timeout = @open_timeout if @open_timeout
710
+
711
+ http.start
712
+
713
+ socket = http.instance_variable_get :@socket
714
+
715
+ if socket then # for fakeweb
716
+ @socket_options.each do |option|
717
+ socket.io.setsockopt(*option)
718
+ end
719
+ end
720
+ end
721
+
722
+ ##
723
+ # Finishes the Gem::Net::HTTP +connection+
724
+
725
+ def finish connection
726
+ connection.finish
727
+
728
+ connection.http.instance_variable_set :@last_communicated, nil
729
+ connection.http.instance_variable_set :@ssl_session, nil unless
730
+ @reuse_ssl_sessions
731
+ end
732
+
733
+ ##
734
+ # Returns the HTTP protocol version for +uri+
735
+
736
+ def http_version uri
737
+ @http_versions["#{uri.hostname}:#{uri.port}"]
738
+ end
739
+
740
+ ##
741
+ # Adds "http://" to the String +uri+ if it is missing.
742
+
743
+ def normalize_uri uri
744
+ (uri =~ /^https?:/) ? uri : "http://#{uri}"
745
+ end
746
+
747
+ ##
748
+ # Set the maximum number of retries for a request.
749
+ #
750
+ # Defaults to one retry.
751
+ #
752
+ # Set this to 0 to disable retries.
753
+
754
+ def max_retries= retries
755
+ retries = retries.to_int
756
+
757
+ raise ArgumentError, "max_retries must be positive" if retries < 0
758
+
759
+ @max_retries = retries
760
+
761
+ reconnect
762
+ end
763
+
764
+ ##
765
+ # Sets this client's SSL private key
766
+
767
+ def private_key= key
768
+ @private_key = key
769
+
770
+ reconnect_ssl
771
+ end
772
+
773
+ # For Gem::Net::HTTP parity
774
+ alias key= private_key=
775
+
776
+ ##
777
+ # Sets the proxy server. The +proxy+ may be the Gem::URI of the proxy server,
778
+ # the symbol +:ENV+ which will read the proxy from the environment or nil to
779
+ # disable use of a proxy. See #proxy_from_env for details on setting the
780
+ # proxy from the environment.
781
+ #
782
+ # If the proxy Gem::URI is set after requests have been made, the next request
783
+ # will shut-down and re-open all connections.
784
+ #
785
+ # The +no_proxy+ query parameter can be used to specify hosts which shouldn't
786
+ # be reached via proxy; if set it should be a comma separated list of
787
+ # hostname suffixes, optionally with +:port+ appended, for example
788
+ # <tt>example.com,some.host:8080</tt>.
789
+
790
+ def proxy= proxy
791
+ @proxy_uri = case proxy
792
+ when :ENV then proxy_from_env
793
+ when Gem::URI::HTTP then proxy
794
+ when nil then # ignore
795
+ else raise ArgumentError, 'proxy must be :ENV or a Gem::URI::HTTP'
796
+ end
797
+
798
+ @no_proxy.clear
799
+
800
+ if @proxy_uri then
801
+ @proxy_args = [
802
+ @proxy_uri.hostname,
803
+ @proxy_uri.port,
804
+ unescape(@proxy_uri.user),
805
+ unescape(@proxy_uri.password),
806
+ ]
807
+
808
+ @proxy_connection_id = [nil, *@proxy_args].join ':'
809
+
810
+ if @proxy_uri.query then
811
+ @no_proxy = Gem::URI.decode_www_form(@proxy_uri.query).filter_map { |k, v| v if k == 'no_proxy' }.join(',').downcase.split(',').map { |x| x.strip }.reject { |x| x.empty? }
812
+ end
813
+ end
814
+
815
+ reconnect
816
+ reconnect_ssl
817
+ end
818
+
819
+ ##
820
+ # Creates a Gem::URI for an HTTP proxy server from ENV variables.
821
+ #
822
+ # If +HTTP_PROXY+ is set a proxy will be returned.
823
+ #
824
+ # If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the Gem::URI is given the
825
+ # indicated user and password unless HTTP_PROXY contains either of these in
826
+ # the Gem::URI.
827
+ #
828
+ # The +NO_PROXY+ ENV variable can be used to specify hosts which shouldn't
829
+ # be reached via proxy; if set it should be a comma separated list of
830
+ # hostname suffixes, optionally with +:port+ appended, for example
831
+ # <tt>example.com,some.host:8080</tt>. When set to <tt>*</tt> no proxy will
832
+ # be returned.
833
+ #
834
+ # For Windows users, lowercase ENV variables are preferred over uppercase ENV
835
+ # variables.
836
+
837
+ def proxy_from_env
838
+ env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
839
+
840
+ return nil if env_proxy.nil? or env_proxy.empty?
841
+
842
+ uri = Gem::URI normalize_uri env_proxy
843
+
844
+ env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']
845
+
846
+ # '*' is special case for always bypass
847
+ return nil if env_no_proxy == '*'
848
+
849
+ if env_no_proxy then
850
+ uri.query = "no_proxy=#{escape(env_no_proxy)}"
851
+ end
852
+
853
+ unless uri.user or uri.password then
854
+ uri.user = escape ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER']
855
+ uri.password = escape ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS']
856
+ end
857
+
858
+ uri
859
+ end
860
+
861
+ ##
862
+ # Returns true when proxy should by bypassed for host.
863
+
864
+ def proxy_bypass? host, port
865
+ host = host.downcase
866
+ host_port = [host, port].join ':'
867
+
868
+ @no_proxy.each do |name|
869
+ return true if host[-name.length, name.length] == name or
870
+ host_port[-name.length, name.length] == name
871
+ end
872
+
873
+ false
874
+ end
875
+
876
+ ##
877
+ # Forces reconnection of all HTTP connections, including TLS/SSL
878
+ # connections.
879
+
880
+ def reconnect
881
+ @generation += 1
882
+ end
883
+
884
+ ##
885
+ # Forces reconnection of only TLS/SSL connections.
886
+
887
+ def reconnect_ssl
888
+ @ssl_generation += 1
889
+ end
890
+
891
+ ##
892
+ # Finishes then restarts the Gem::Net::HTTP +connection+
893
+
894
+ def reset connection
895
+ http = connection.http
896
+
897
+ finish connection
898
+
899
+ start http
900
+ rescue Errno::ECONNREFUSED
901
+ e = Error.new "connection refused: #{http.address}:#{http.port}"
902
+ e.set_backtrace $@
903
+ raise e
904
+ rescue Errno::EHOSTDOWN
905
+ e = Error.new "host down: #{http.address}:#{http.port}"
906
+ e.set_backtrace $@
907
+ raise e
908
+ end
909
+
910
+ ##
911
+ # Makes a request on +uri+. If +req+ is nil a Gem::Net::HTTP::Get is performed
912
+ # against +uri+.
913
+ #
914
+ # If a block is passed #request behaves like Gem::Net::HTTP#request (the body of
915
+ # the response will not have been read).
916
+ #
917
+ # +req+ must be a Gem::Net::HTTPGenericRequest subclass (see Gem::Net::HTTP for a list).
918
+
919
+ def request uri, req = nil, &block
920
+ uri = Gem::URI uri
921
+ req = request_setup req || uri
922
+ response = nil
923
+
924
+ connection_for uri do |connection|
925
+ http = connection.http
926
+
927
+ begin
928
+ connection.requests += 1
929
+
930
+ response = http.request req, &block
931
+
932
+ if req.connection_close? or
933
+ (response.http_version <= '1.0' and
934
+ not response.connection_keep_alive?) or
935
+ response.connection_close? then
936
+ finish connection
937
+ end
938
+ rescue Exception # make sure to close the connection when it was interrupted
939
+ finish connection
940
+
941
+ raise
942
+ ensure
943
+ connection.last_use = Time.now
944
+ end
945
+ end
946
+
947
+ @http_versions["#{uri.hostname}:#{uri.port}"] ||= response.http_version
948
+
949
+ response
950
+ end
951
+
952
+ ##
953
+ # Creates a GET request if +req_or_uri+ is a Gem::URI and adds headers to the
954
+ # request.
955
+ #
956
+ # Returns the request.
957
+
958
+ def request_setup req_or_uri # :nodoc:
959
+ req = if req_or_uri.respond_to? 'request_uri' then
960
+ Gem::Net::HTTP::Get.new req_or_uri.request_uri
961
+ else
962
+ req_or_uri
963
+ end
964
+
965
+ @headers.each do |pair|
966
+ req.add_field(*pair)
967
+ end
968
+
969
+ @override_headers.each do |name, value|
970
+ req[name] = value
971
+ end
972
+
973
+ unless req['Connection'] then
974
+ req.add_field 'Connection', 'keep-alive'
975
+ req.add_field 'Keep-Alive', @keep_alive
976
+ end
977
+
978
+ req
979
+ end
980
+
981
+ ##
982
+ # Shuts down all connections. Attempting to checkout a connection after
983
+ # shutdown will raise an error.
984
+ #
985
+ # *NOTE*: Calling shutdown for can be dangerous!
986
+ #
987
+ # If any thread is still using a connection it may cause an error! Call
988
+ # #shutdown when you are completely done making requests!
989
+
990
+ def shutdown
991
+ @pool.shutdown { |http| http.finish }
992
+ end
993
+
994
+ ##
995
+ # Discard all existing connections. Subsequent checkouts will create
996
+ # new connections as needed.
997
+ #
998
+ # If any thread is still using a connection it may cause an error! Call
999
+ # #reload when you are completely done making requests!
1000
+
1001
+ def reload
1002
+ @pool.reload { |http| http.finish }
1003
+ end
1004
+
1005
+ ##
1006
+ # Enables SSL on +connection+
1007
+
1008
+ def ssl connection
1009
+ connection.use_ssl = true
1010
+
1011
+ connection.ciphers = @ciphers if @ciphers
1012
+ connection.ssl_timeout = @ssl_timeout if @ssl_timeout
1013
+ connection.ssl_version = @ssl_version if @ssl_version
1014
+ connection.min_version = @min_version if @min_version
1015
+ connection.max_version = @max_version if @max_version
1016
+
1017
+ connection.verify_depth = @verify_depth
1018
+ connection.verify_mode = @verify_mode
1019
+ connection.verify_hostname = @verify_hostname if
1020
+ @verify_hostname != nil && connection.respond_to?(:verify_hostname=)
1021
+
1022
+ if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
1023
+ not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
1024
+ warn <<-WARNING
1025
+ !!!SECURITY WARNING!!!
1026
+
1027
+ The SSL HTTP connection to:
1028
+
1029
+ #{connection.address}:#{connection.port}
1030
+
1031
+ !!!MAY NOT BE VERIFIED!!!
1032
+
1033
+ On your platform your OpenSSL implementation is broken.
1034
+
1035
+ There is no difference between the values of VERIFY_NONE and VERIFY_PEER.
1036
+
1037
+ This means that attempting to verify the security of SSL connections may not
1038
+ work. This exposes you to man-in-the-middle exploits, snooping on the
1039
+ contents of your connection and other dangers to the security of your data.
1040
+
1041
+ To disable this warning define the following constant at top-level in your
1042
+ application:
1043
+
1044
+ I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG = nil
1045
+
1046
+ WARNING
1047
+ end
1048
+
1049
+ connection.ca_file = @ca_file if @ca_file
1050
+ connection.ca_path = @ca_path if @ca_path
1051
+
1052
+ if @ca_file or @ca_path then
1053
+ connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
1054
+ connection.verify_callback = @verify_callback if @verify_callback
1055
+ end
1056
+
1057
+ if @certificate and @private_key then
1058
+ connection.cert = @certificate
1059
+ connection.key = @private_key
1060
+ end
1061
+
1062
+ if defined?(@extra_chain_cert) and @extra_chain_cert
1063
+ connection.extra_chain_cert = @extra_chain_cert
1064
+ end
1065
+
1066
+ connection.cert_store = if @cert_store then
1067
+ @cert_store
1068
+ else
1069
+ store = OpenSSL::X509::Store.new
1070
+ store.set_default_paths
1071
+ store
1072
+ end
1073
+ end
1074
+
1075
+ ##
1076
+ # SSL session lifetime
1077
+
1078
+ def ssl_timeout= ssl_timeout
1079
+ @ssl_timeout = ssl_timeout
1080
+
1081
+ reconnect_ssl
1082
+ end
1083
+
1084
+ ##
1085
+ # SSL version to use
1086
+
1087
+ def ssl_version= ssl_version
1088
+ @ssl_version = ssl_version
1089
+
1090
+ reconnect_ssl
1091
+ end
1092
+
1093
+ ##
1094
+ # Minimum SSL version to use
1095
+
1096
+ def min_version= min_version
1097
+ @min_version = min_version
1098
+
1099
+ reconnect_ssl
1100
+ end
1101
+
1102
+ ##
1103
+ # maximum SSL version to use
1104
+
1105
+ def max_version= max_version
1106
+ @max_version = max_version
1107
+
1108
+ reconnect_ssl
1109
+ end
1110
+
1111
+ ##
1112
+ # Sets the depth of SSL certificate verification
1113
+
1114
+ def verify_depth= verify_depth
1115
+ @verify_depth = verify_depth
1116
+
1117
+ reconnect_ssl
1118
+ end
1119
+
1120
+ ##
1121
+ # Sets the HTTPS verify mode. Defaults to OpenSSL::SSL::VERIFY_PEER.
1122
+ #
1123
+ # Setting this to VERIFY_NONE is a VERY BAD IDEA and should NEVER be used.
1124
+ # Securely transfer the correct certificate and update the default
1125
+ # certificate store or set the ca file instead.
1126
+
1127
+ def verify_mode= verify_mode
1128
+ @verify_mode = verify_mode
1129
+
1130
+ reconnect_ssl
1131
+ end
1132
+
1133
+ ##
1134
+ # Sets the HTTPS verify_hostname.
1135
+
1136
+ def verify_hostname= verify_hostname
1137
+ @verify_hostname = verify_hostname
1138
+
1139
+ reconnect_ssl
1140
+ end
1141
+
1142
+ ##
1143
+ # SSL verification callback.
1144
+
1145
+ def verify_callback= callback
1146
+ @verify_callback = callback
1147
+
1148
+ reconnect_ssl
1149
+ end
1150
+ end
1151
+
1152
+ require_relative 'persistent/connection'
1153
+ require_relative 'persistent/pool'