rubygems-update 3.3.18 → 3.6.2

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 (832) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2182 -1067
  3. data/CODE_OF_CONDUCT.md +79 -28
  4. data/Manifest.txt +184 -290
  5. data/README.md +35 -19
  6. data/bundler/CHANGELOG.md +1003 -3
  7. data/bundler/README.md +3 -7
  8. data/bundler/bundler.gemspec +11 -11
  9. data/bundler/exe/bundle +5 -25
  10. data/bundler/lib/bundler/build_metadata.rb +3 -3
  11. data/bundler/lib/bundler/capistrano.rb +1 -1
  12. data/bundler/lib/bundler/checksum.rb +254 -0
  13. data/bundler/lib/bundler/ci_detector.rb +75 -0
  14. data/bundler/lib/bundler/cli/add.rb +7 -5
  15. data/bundler/lib/bundler/cli/binstubs.rb +10 -6
  16. data/bundler/lib/bundler/cli/cache.rb +1 -1
  17. data/bundler/lib/bundler/cli/check.rb +4 -4
  18. data/bundler/lib/bundler/cli/common.rb +11 -1
  19. data/bundler/lib/bundler/cli/config.rb +8 -7
  20. data/bundler/lib/bundler/cli/console.rb +2 -5
  21. data/bundler/lib/bundler/cli/doctor.rb +10 -12
  22. data/bundler/lib/bundler/cli/exec.rb +2 -1
  23. data/bundler/lib/bundler/cli/fund.rb +1 -1
  24. data/bundler/lib/bundler/cli/gem.rb +77 -53
  25. data/bundler/lib/bundler/cli/info.rb +4 -15
  26. data/bundler/lib/bundler/cli/init.rb +6 -2
  27. data/bundler/lib/bundler/cli/inject.rb +1 -1
  28. data/bundler/lib/bundler/cli/install.rb +27 -15
  29. data/bundler/lib/bundler/cli/issue.rb +1 -1
  30. data/bundler/lib/bundler/cli/lock.rb +54 -28
  31. data/bundler/lib/bundler/cli/open.rb +9 -9
  32. data/bundler/lib/bundler/cli/outdated.rb +34 -29
  33. data/bundler/lib/bundler/cli/platform.rb +7 -5
  34. data/bundler/lib/bundler/cli/plugin.rb +9 -15
  35. data/bundler/lib/bundler/cli/pristine.rb +38 -30
  36. data/bundler/lib/bundler/cli/show.rb +4 -4
  37. data/bundler/lib/bundler/cli/update.rb +6 -5
  38. data/bundler/lib/bundler/cli/viz.rb +1 -1
  39. data/bundler/lib/bundler/cli.rb +258 -307
  40. data/bundler/lib/bundler/compact_index_client/cache.rb +55 -60
  41. data/bundler/lib/bundler/compact_index_client/cache_file.rb +148 -0
  42. data/bundler/lib/bundler/compact_index_client/gem_parser.rb +7 -3
  43. data/bundler/lib/bundler/compact_index_client/parser.rb +84 -0
  44. data/bundler/lib/bundler/compact_index_client/updater.rb +71 -83
  45. data/bundler/lib/bundler/compact_index_client.rb +58 -80
  46. data/bundler/lib/bundler/constants.rb +9 -2
  47. data/bundler/lib/bundler/current_ruby.rb +11 -16
  48. data/bundler/lib/bundler/definition.rb +547 -228
  49. data/bundler/lib/bundler/dependency.rb +30 -87
  50. data/bundler/lib/bundler/digest.rb +3 -3
  51. data/bundler/lib/bundler/dsl.rb +115 -65
  52. data/bundler/lib/bundler/endpoint_specification.rb +27 -14
  53. data/bundler/lib/bundler/env.rb +5 -7
  54. data/bundler/lib/bundler/environment_preserver.rb +8 -25
  55. data/bundler/lib/bundler/errors.rb +85 -11
  56. data/bundler/lib/bundler/feature_flag.rb +1 -2
  57. data/bundler/lib/bundler/fetcher/base.rb +5 -3
  58. data/bundler/lib/bundler/fetcher/compact_index.rb +28 -43
  59. data/bundler/lib/bundler/fetcher/dependency.rb +3 -7
  60. data/bundler/lib/bundler/fetcher/downloader.rb +17 -16
  61. data/bundler/lib/bundler/fetcher/gem_remote_fetcher.rb +16 -0
  62. data/bundler/lib/bundler/fetcher/index.rb +2 -3
  63. data/bundler/lib/bundler/fetcher.rb +91 -74
  64. data/bundler/lib/bundler/force_platform.rb +16 -0
  65. data/bundler/lib/bundler/friendly_errors.rb +6 -9
  66. data/bundler/lib/bundler/gem_helper.rb +5 -6
  67. data/bundler/lib/bundler/gem_helpers.rb +45 -7
  68. data/bundler/lib/bundler/gem_version_promoter.rb +68 -109
  69. data/bundler/lib/bundler/graph.rb +9 -9
  70. data/bundler/lib/bundler/index.rb +69 -73
  71. data/bundler/lib/bundler/injector.rb +12 -13
  72. data/bundler/lib/bundler/inline.rb +40 -17
  73. data/bundler/lib/bundler/installer/gem_installer.rb +13 -12
  74. data/bundler/lib/bundler/installer/parallel_installer.rb +19 -66
  75. data/bundler/lib/bundler/installer/standalone.rb +29 -15
  76. data/bundler/lib/bundler/installer.rb +27 -77
  77. data/bundler/lib/bundler/lazy_specification.rb +134 -71
  78. data/bundler/lib/bundler/lockfile_generator.rb +13 -4
  79. data/bundler/lib/bundler/lockfile_parser.rb +134 -61
  80. data/bundler/lib/bundler/man/bundle-add.1 +46 -48
  81. data/bundler/lib/bundler/man/bundle-add.1.ronn +54 -22
  82. data/bundler/lib/bundler/man/bundle-binstubs.1 +10 -19
  83. data/bundler/lib/bundler/man/bundle-binstubs.1.ronn +6 -3
  84. data/bundler/lib/bundler/man/bundle-cache.1 +38 -25
  85. data/bundler/lib/bundler/man/bundle-cache.1.ronn +40 -4
  86. data/bundler/lib/bundler/man/bundle-check.1 +7 -14
  87. data/bundler/lib/bundler/man/bundle-check.1.ronn +7 -2
  88. data/bundler/lib/bundler/man/bundle-clean.1 +4 -11
  89. data/bundler/lib/bundler/man/bundle-clean.1.ronn +1 -1
  90. data/bundler/lib/bundler/man/bundle-config.1 +41 -220
  91. data/bundler/lib/bundler/man/bundle-config.1.ronn +27 -22
  92. data/bundler/lib/bundler/man/bundle-console.1 +33 -0
  93. data/bundler/lib/bundler/man/bundle-console.1.ronn +39 -0
  94. data/bundler/lib/bundler/man/bundle-doctor.1 +5 -19
  95. data/bundler/lib/bundler/man/bundle-doctor.1.ronn +1 -1
  96. data/bundler/lib/bundler/man/bundle-env.1 +9 -0
  97. data/bundler/lib/bundler/man/bundle-env.1.ronn +10 -0
  98. data/bundler/lib/bundler/man/bundle-exec.1 +20 -78
  99. data/bundler/lib/bundler/man/bundle-exec.1.ronn +12 -10
  100. data/bundler/lib/bundler/man/bundle-fund.1 +22 -0
  101. data/bundler/lib/bundler/man/bundle-fund.1.ronn +25 -0
  102. data/bundler/lib/bundler/man/bundle-gem.1 +53 -81
  103. data/bundler/lib/bundler/man/bundle-gem.1.ronn +41 -9
  104. data/bundler/lib/bundler/man/bundle-help.1 +9 -0
  105. data/bundler/lib/bundler/man/bundle-help.1.ronn +12 -0
  106. data/bundler/lib/bundler/man/bundle-info.1 +8 -11
  107. data/bundler/lib/bundler/man/bundle-info.1.ronn +9 -5
  108. data/bundler/lib/bundler/man/bundle-init.1 +7 -12
  109. data/bundler/lib/bundler/man/bundle-init.1.ronn +4 -1
  110. data/bundler/lib/bundler/man/bundle-inject.1 +17 -19
  111. data/bundler/lib/bundler/man/bundle-inject.1.ronn +12 -2
  112. data/bundler/lib/bundler/man/bundle-install.1 +42 -162
  113. data/bundler/lib/bundler/man/bundle-install.1.ronn +31 -49
  114. data/bundler/lib/bundler/man/bundle-issue.1 +45 -0
  115. data/bundler/lib/bundler/man/bundle-issue.1.ronn +37 -0
  116. data/bundler/lib/bundler/man/bundle-licenses.1 +9 -0
  117. data/bundler/lib/bundler/man/bundle-licenses.1.ronn +10 -0
  118. data/bundler/lib/bundler/man/bundle-list.1 +4 -19
  119. data/bundler/lib/bundler/man/bundle-list.1.ronn +4 -1
  120. data/bundler/lib/bundler/man/bundle-lock.1 +25 -34
  121. data/bundler/lib/bundler/man/bundle-lock.1.ronn +25 -4
  122. data/bundler/lib/bundler/man/bundle-open.1 +18 -18
  123. data/bundler/lib/bundler/man/bundle-open.1.ronn +10 -1
  124. data/bundler/lib/bundler/man/bundle-outdated.1 +22 -67
  125. data/bundler/lib/bundler/man/bundle-outdated.1.ronn +20 -12
  126. data/bundler/lib/bundler/man/bundle-platform.1 +16 -28
  127. data/bundler/lib/bundler/man/bundle-platform.1.ronn +14 -7
  128. data/bundler/lib/bundler/man/bundle-plugin.1 +58 -0
  129. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +63 -0
  130. data/bundler/lib/bundler/man/bundle-pristine.1 +5 -16
  131. data/bundler/lib/bundler/man/bundle-pristine.1.ronn +1 -1
  132. data/bundler/lib/bundler/man/bundle-remove.1 +4 -14
  133. data/bundler/lib/bundler/man/bundle-remove.1.ronn +1 -1
  134. data/bundler/lib/bundler/man/bundle-show.1 +7 -11
  135. data/bundler/lib/bundler/man/bundle-show.1.ronn +4 -0
  136. data/bundler/lib/bundler/man/bundle-update.1 +30 -143
  137. data/bundler/lib/bundler/man/bundle-update.1.ronn +14 -6
  138. data/bundler/lib/bundler/man/bundle-version.1 +22 -0
  139. data/bundler/lib/bundler/man/bundle-version.1.ronn +24 -0
  140. data/bundler/lib/bundler/man/bundle-viz.1 +9 -18
  141. data/bundler/lib/bundler/man/bundle-viz.1.ronn +9 -3
  142. data/bundler/lib/bundler/man/bundle.1 +17 -51
  143. data/bundler/lib/bundler/man/bundle.1.ronn +12 -7
  144. data/bundler/lib/bundler/man/gemfile.5 +77 -341
  145. data/bundler/lib/bundler/man/gemfile.5.ronn +73 -54
  146. data/bundler/lib/bundler/man/index.txt +8 -0
  147. data/bundler/lib/bundler/match_metadata.rb +17 -0
  148. data/bundler/lib/bundler/match_platform.rb +1 -1
  149. data/bundler/lib/bundler/match_remote_metadata.rb +29 -0
  150. data/bundler/lib/bundler/materialization.rb +59 -0
  151. data/bundler/lib/bundler/mirror.rb +8 -10
  152. data/bundler/lib/bundler/plugin/api/source.rb +7 -5
  153. data/bundler/lib/bundler/plugin/events.rb +24 -0
  154. data/bundler/lib/bundler/plugin/index.rb +13 -5
  155. data/bundler/lib/bundler/plugin/installer/path.rb +18 -0
  156. data/bundler/lib/bundler/plugin/installer/rubygems.rb +0 -4
  157. data/bundler/lib/bundler/plugin/installer.rb +42 -19
  158. data/bundler/lib/bundler/plugin/source_list.rb +4 -4
  159. data/bundler/lib/bundler/plugin.rb +35 -7
  160. data/bundler/lib/bundler/process_lock.rb +10 -14
  161. data/bundler/lib/bundler/remote_specification.rb +17 -13
  162. data/bundler/lib/bundler/resolver/base.rb +117 -0
  163. data/bundler/lib/bundler/resolver/candidate.rb +82 -0
  164. data/bundler/lib/bundler/resolver/incompatibility.rb +15 -0
  165. data/bundler/lib/bundler/resolver/package.rb +90 -0
  166. data/bundler/lib/bundler/resolver/root.rb +25 -0
  167. data/bundler/lib/bundler/resolver/spec_group.rb +54 -67
  168. data/bundler/lib/bundler/resolver.rb +432 -329
  169. data/bundler/lib/bundler/retry.rb +2 -2
  170. data/bundler/lib/bundler/ruby_dsl.rb +42 -7
  171. data/bundler/lib/bundler/ruby_version.rb +23 -10
  172. data/bundler/lib/bundler/rubygems_ext.rb +286 -81
  173. data/bundler/lib/bundler/rubygems_gem_installer.rb +77 -68
  174. data/bundler/lib/bundler/rubygems_integration.rb +57 -155
  175. data/bundler/lib/bundler/runtime.rb +28 -17
  176. data/bundler/lib/bundler/safe_marshal.rb +31 -0
  177. data/bundler/lib/bundler/self_manager.rb +50 -12
  178. data/bundler/lib/bundler/settings.rb +144 -58
  179. data/bundler/lib/bundler/setup.rb +13 -1
  180. data/bundler/lib/bundler/shared_helpers.rb +87 -36
  181. data/bundler/lib/bundler/source/git/git_proxy.rb +278 -80
  182. data/bundler/lib/bundler/source/git.rb +161 -68
  183. data/bundler/lib/bundler/source/metadata.rb +16 -16
  184. data/bundler/lib/bundler/source/path/installer.rb +1 -22
  185. data/bundler/lib/bundler/source/path.rb +16 -26
  186. data/bundler/lib/bundler/source/rubygems/remote.rb +1 -1
  187. data/bundler/lib/bundler/source/rubygems.rb +94 -154
  188. data/bundler/lib/bundler/source.rb +3 -1
  189. data/bundler/lib/bundler/source_list.rb +34 -4
  190. data/bundler/lib/bundler/spec_set.rb +195 -65
  191. data/bundler/lib/bundler/stub_specification.rb +34 -4
  192. data/bundler/lib/bundler/templates/Executable +1 -1
  193. data/bundler/lib/bundler/templates/Executable.bundler +6 -11
  194. data/bundler/lib/bundler/templates/Executable.standalone +2 -0
  195. data/bundler/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +77 -29
  196. data/bundler/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
  197. data/bundler/lib/bundler/templates/newgem/README.md.tt +11 -5
  198. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +19 -8
  199. data/bundler/lib/bundler/templates/newgem/bin/console.tt +0 -4
  200. data/bundler/lib/bundler/templates/newgem/circleci/config.yml.tt +12 -0
  201. data/bundler/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
  202. data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
  203. data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  204. data/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +1 -1
  205. data/bundler/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
  206. data/bundler/lib/bundler/templates/newgem/github/workflows/main.yml.tt +18 -8
  207. data/bundler/lib/bundler/templates/newgem/gitignore.tt +3 -0
  208. data/bundler/lib/bundler/templates/newgem/gitlab-ci.yml.tt +13 -4
  209. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +12 -4
  210. data/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +0 -5
  211. data/bundler/lib/bundler/templates/newgem/standard.yml.tt +1 -1
  212. data/bundler/lib/bundler/ui/rg_proxy.rb +1 -1
  213. data/bundler/lib/bundler/ui/shell.rb +60 -15
  214. data/bundler/lib/bundler/ui/silent.rb +33 -6
  215. data/bundler/lib/bundler/uri_credentials_filter.rb +3 -3
  216. data/bundler/lib/bundler/uri_normalizer.rb +23 -0
  217. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +3 -3
  218. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
  219. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +0 -1
  220. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +56 -7
  221. data/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb +1350 -418
  222. data/bundler/lib/bundler/vendor/net-http-persistent/.document +1 -0
  223. data/bundler/lib/bundler/vendor/net-http-persistent/README.rdoc +1 -1
  224. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +4 -3
  225. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +23 -11
  226. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +1 -1
  227. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +102 -64
  228. data/bundler/lib/bundler/vendor/pub_grub/.document +1 -0
  229. data/bundler/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  230. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  231. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
  232. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  233. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
  234. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  235. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  236. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  237. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  238. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +61 -0
  239. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  240. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  241. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
  242. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +411 -0
  243. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +248 -0
  244. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  245. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  246. data/bundler/lib/bundler/vendor/securerandom/.document +1 -0
  247. data/bundler/lib/bundler/vendor/securerandom/COPYING +56 -0
  248. data/bundler/lib/bundler/vendor/securerandom/lib/securerandom.rb +102 -0
  249. data/bundler/lib/bundler/vendor/thor/.document +1 -0
  250. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +3 -2
  251. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +1 -1
  252. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +1 -1
  253. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +11 -15
  254. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +15 -4
  255. data/bundler/lib/bundler/vendor/thor/lib/thor/actions.rb +15 -15
  256. data/bundler/lib/bundler/vendor/thor/lib/thor/base.rb +140 -14
  257. data/bundler/lib/bundler/vendor/thor/lib/thor/command.rb +13 -4
  258. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +4 -0
  259. data/bundler/lib/bundler/vendor/thor/lib/thor/error.rb +16 -25
  260. data/bundler/lib/bundler/vendor/thor/lib/thor/group.rb +12 -1
  261. data/bundler/lib/bundler/vendor/thor/lib/thor/invocation.rb +1 -1
  262. data/bundler/lib/bundler/vendor/thor/lib/thor/nested_context.rb +2 -2
  263. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +17 -1
  264. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +33 -17
  265. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/option.rb +28 -9
  266. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb +46 -7
  267. data/bundler/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +2 -2
  268. data/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb +40 -30
  269. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +35 -159
  270. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/color.rb +1 -46
  271. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
  272. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/html.rb +1 -46
  273. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +118 -0
  274. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
  275. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
  276. data/bundler/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
  277. data/bundler/lib/bundler/vendor/thor/lib/thor/util.rb +8 -7
  278. data/bundler/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
  279. data/bundler/lib/bundler/vendor/thor/lib/thor.rb +166 -8
  280. data/bundler/lib/bundler/vendor/tsort/.document +1 -0
  281. data/bundler/lib/bundler/vendor/tsort/lib/tsort.rb +3 -0
  282. data/bundler/lib/bundler/vendor/uri/.document +1 -0
  283. data/bundler/lib/bundler/vendor/uri/COPYING +56 -0
  284. data/bundler/lib/bundler/vendor/uri/lib/uri/common.rb +343 -148
  285. data/bundler/lib/bundler/vendor/uri/lib/uri/file.rb +10 -4
  286. data/bundler/lib/bundler/vendor/uri/lib/uri/ftp.rb +3 -2
  287. data/bundler/lib/bundler/vendor/uri/lib/uri/generic.rb +44 -33
  288. data/bundler/lib/bundler/vendor/uri/lib/uri/http.rb +40 -2
  289. data/bundler/lib/bundler/vendor/uri/lib/uri/https.rb +2 -1
  290. data/bundler/lib/bundler/vendor/uri/lib/uri/ldap.rb +1 -1
  291. data/bundler/lib/bundler/vendor/uri/lib/uri/ldaps.rb +2 -1
  292. data/bundler/lib/bundler/vendor/uri/lib/uri/mailto.rb +2 -2
  293. data/bundler/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +25 -12
  294. data/bundler/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +130 -38
  295. data/bundler/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  296. data/bundler/lib/bundler/vendor/uri/lib/uri/ws.rb +1 -2
  297. data/bundler/lib/bundler/vendor/uri/lib/uri/wss.rb +2 -1
  298. data/bundler/lib/bundler/vendor/uri/lib/uri.rb +12 -11
  299. data/bundler/lib/bundler/vendored_net_http.rb +23 -0
  300. data/bundler/lib/bundler/vendored_persistent.rb +0 -36
  301. data/bundler/lib/bundler/{vendored_tmpdir.rb → vendored_pub_grub.rb} +1 -1
  302. data/bundler/lib/bundler/vendored_securerandom.rb +12 -0
  303. data/bundler/lib/bundler/vendored_timeout.rb +12 -0
  304. data/bundler/lib/bundler/vendored_uri.rb +18 -1
  305. data/bundler/lib/bundler/version.rb +5 -1
  306. data/bundler/lib/bundler/vlad.rb +1 -1
  307. data/bundler/lib/bundler/worker.rb +5 -7
  308. data/bundler/lib/bundler/yaml_serializer.rb +22 -13
  309. data/bundler/lib/bundler.rb +155 -148
  310. data/{bundler → doc/bundler}/UPGRADING.md +11 -4
  311. data/{CONTRIBUTING.md → doc/rubygems/CONTRIBUTING.md} +40 -17
  312. data/doc/rubygems/POLICIES.md +204 -0
  313. data/{test/rubygems/fake_certlib/openssl.rb → exe/gem} +5 -1
  314. data/{bin → exe}/update_rubygems +12 -10
  315. data/lib/rubygems/available_set.rb +8 -7
  316. data/lib/rubygems/basic_specification.rb +90 -52
  317. data/lib/rubygems/bundler_version_finder.rb +6 -6
  318. data/lib/rubygems/ci_detector.rb +75 -0
  319. data/lib/rubygems/command.rb +68 -64
  320. data/lib/rubygems/command_manager.rb +39 -24
  321. data/lib/rubygems/commands/build_command.rb +14 -19
  322. data/lib/rubygems/commands/cert_command.rb +39 -39
  323. data/lib/rubygems/commands/check_command.rb +30 -25
  324. data/lib/rubygems/commands/cleanup_command.rb +32 -43
  325. data/lib/rubygems/commands/contents_command.rb +33 -25
  326. data/lib/rubygems/commands/dependency_command.rb +22 -23
  327. data/lib/rubygems/commands/environment_command.rb +8 -9
  328. data/lib/rubygems/commands/exec_command.rb +247 -0
  329. data/lib/rubygems/commands/fetch_command.rb +25 -10
  330. data/lib/rubygems/commands/generate_index_command.rb +40 -74
  331. data/lib/rubygems/commands/help_command.rb +15 -14
  332. data/lib/rubygems/commands/info_command.rb +5 -5
  333. data/lib/rubygems/commands/install_command.rb +31 -38
  334. data/lib/rubygems/commands/list_command.rb +6 -5
  335. data/lib/rubygems/commands/lock_command.rb +6 -5
  336. data/lib/rubygems/commands/mirror_command.rb +4 -3
  337. data/lib/rubygems/commands/open_command.rb +11 -12
  338. data/lib/rubygems/commands/outdated_command.rb +6 -5
  339. data/lib/rubygems/commands/owner_command.rb +23 -22
  340. data/lib/rubygems/commands/pristine_command.rb +83 -62
  341. data/lib/rubygems/commands/push_command.rb +38 -13
  342. data/lib/rubygems/commands/query_command.rb +11 -11
  343. data/lib/rubygems/commands/rdoc_command.rb +23 -28
  344. data/lib/rubygems/commands/rebuild_command.rb +262 -0
  345. data/lib/rubygems/commands/search_command.rb +6 -5
  346. data/lib/rubygems/commands/server_command.rb +4 -3
  347. data/lib/rubygems/commands/setup_command.rb +137 -154
  348. data/lib/rubygems/commands/signin_command.rb +10 -9
  349. data/lib/rubygems/commands/signout_command.rb +8 -7
  350. data/lib/rubygems/commands/sources_command.rb +34 -33
  351. data/lib/rubygems/commands/specification_command.rb +25 -20
  352. data/lib/rubygems/commands/stale_command.rb +5 -4
  353. data/lib/rubygems/commands/uninstall_command.rb +66 -59
  354. data/lib/rubygems/commands/unpack_command.rb +23 -30
  355. data/lib/rubygems/commands/update_command.rb +62 -94
  356. data/lib/rubygems/commands/which_command.rb +9 -8
  357. data/lib/rubygems/commands/yank_command.rb +14 -13
  358. data/lib/rubygems/compatibility.rb +5 -6
  359. data/lib/rubygems/config_file.rb +160 -50
  360. data/lib/rubygems/core_ext/kernel_gem.rb +3 -10
  361. data/lib/rubygems/core_ext/kernel_require.rb +88 -114
  362. data/lib/rubygems/core_ext/kernel_warn.rb +30 -39
  363. data/lib/rubygems/core_ext/tcpsocket_init.rb +4 -2
  364. data/lib/rubygems/defaults.rb +53 -22
  365. data/lib/rubygems/dependency.rb +34 -36
  366. data/lib/rubygems/dependency_installer.rb +52 -56
  367. data/lib/rubygems/dependency_list.rb +8 -7
  368. data/lib/rubygems/deprecate.rb +80 -75
  369. data/lib/rubygems/doctor.rb +23 -22
  370. data/lib/rubygems/errors.rb +6 -8
  371. data/lib/rubygems/exceptions.rb +20 -18
  372. data/lib/rubygems/ext/build_error.rb +2 -1
  373. data/lib/rubygems/ext/builder.rb +56 -32
  374. data/lib/rubygems/ext/cargo_builder/link_flag_converter.rb +9 -5
  375. data/lib/rubygems/ext/cargo_builder.rb +158 -131
  376. data/lib/rubygems/ext/cmake_builder.rb +9 -4
  377. data/lib/rubygems/ext/configure_builder.rb +9 -3
  378. data/lib/rubygems/ext/ext_conf_builder.rb +19 -15
  379. data/lib/rubygems/ext/rake_builder.rb +14 -7
  380. data/lib/rubygems/ext.rb +8 -7
  381. data/lib/rubygems/gem_runner.rb +23 -9
  382. data/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb +163 -0
  383. data/lib/rubygems/gemcutter_utilities/webauthn_listener.rb +105 -0
  384. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +80 -0
  385. data/lib/rubygems/gemcutter_utilities.rb +141 -63
  386. data/lib/rubygems/gemspec_helpers.rb +19 -0
  387. data/lib/rubygems/install_default_message.rb +3 -2
  388. data/lib/rubygems/install_message.rb +3 -2
  389. data/lib/rubygems/install_update_options.rb +72 -67
  390. data/lib/rubygems/installer.rb +148 -130
  391. data/lib/rubygems/installer_uninstaller_utils.rb +2 -4
  392. data/lib/rubygems/local_remote_options.rb +24 -28
  393. data/lib/rubygems/name_tuple.rb +10 -11
  394. data/lib/rubygems/package/digest_io.rb +2 -1
  395. data/lib/rubygems/package/file_source.rb +3 -2
  396. data/lib/rubygems/package/io_source.rb +1 -0
  397. data/lib/rubygems/package/old.rb +11 -10
  398. data/lib/rubygems/package/source.rb +1 -0
  399. data/lib/rubygems/package/tar_header.rb +125 -91
  400. data/lib/rubygems/package/tar_reader/entry.rb +106 -29
  401. data/lib/rubygems/package/tar_reader.rb +16 -39
  402. data/lib/rubygems/package/tar_writer.rb +29 -26
  403. data/lib/rubygems/package.rb +122 -84
  404. data/lib/rubygems/package_task.rb +7 -6
  405. data/lib/rubygems/path_support.rb +11 -11
  406. data/lib/rubygems/platform.rb +119 -70
  407. data/lib/rubygems/psych_tree.rb +6 -1
  408. data/lib/rubygems/query_utils.rb +46 -48
  409. data/lib/rubygems/rdoc.rb +13 -3
  410. data/lib/rubygems/remote_fetcher.rb +47 -39
  411. data/lib/rubygems/request/connection_pools.rb +6 -6
  412. data/lib/rubygems/request/http_pool.rb +2 -1
  413. data/lib/rubygems/request/https_pool.rb +1 -0
  414. data/lib/rubygems/request.rb +48 -44
  415. data/lib/rubygems/request_set/gem_dependency_api.rb +141 -144
  416. data/lib/rubygems/request_set/lockfile/parser.rb +31 -30
  417. data/lib/rubygems/request_set/lockfile/tokenizer.rb +24 -14
  418. data/lib/rubygems/request_set/lockfile.rb +11 -15
  419. data/lib/rubygems/request_set.rb +25 -23
  420. data/lib/rubygems/requirement.rb +30 -27
  421. data/lib/rubygems/resolver/activation_request.rb +7 -10
  422. data/lib/rubygems/resolver/api_set/gem_parser.rb +7 -3
  423. data/lib/rubygems/resolver/api_set.rb +20 -13
  424. data/lib/rubygems/resolver/api_specification.rb +8 -7
  425. data/lib/rubygems/resolver/best_set.rb +5 -32
  426. data/lib/rubygems/resolver/composed_set.rb +4 -3
  427. data/lib/rubygems/resolver/conflict.rb +14 -21
  428. data/lib/rubygems/resolver/current_set.rb +1 -0
  429. data/lib/rubygems/resolver/dependency_request.rb +3 -2
  430. data/lib/rubygems/resolver/git_set.rb +2 -2
  431. data/lib/rubygems/resolver/git_specification.rb +7 -6
  432. data/lib/rubygems/resolver/index_set.rb +10 -9
  433. data/lib/rubygems/resolver/index_specification.rb +8 -6
  434. data/lib/rubygems/resolver/installed_specification.rb +6 -5
  435. data/lib/rubygems/resolver/installer_set.rb +19 -22
  436. data/lib/rubygems/resolver/local_specification.rb +4 -3
  437. data/lib/rubygems/resolver/lock_set.rb +6 -5
  438. data/lib/rubygems/resolver/lock_specification.rb +5 -4
  439. data/lib/rubygems/resolver/requirement_list.rb +1 -0
  440. data/lib/rubygems/resolver/set.rb +1 -0
  441. data/lib/rubygems/resolver/source_set.rb +2 -0
  442. data/lib/rubygems/resolver/spec_specification.rb +8 -0
  443. data/lib/rubygems/resolver/specification.rb +2 -1
  444. data/lib/rubygems/resolver/stats.rb +2 -1
  445. data/lib/rubygems/resolver/vendor_set.rb +2 -1
  446. data/lib/rubygems/resolver/vendor_specification.rb +4 -3
  447. data/lib/rubygems/resolver.rb +51 -57
  448. data/lib/rubygems/s3_uri_signer.rb +18 -16
  449. data/lib/rubygems/safe_marshal/elements.rb +146 -0
  450. data/lib/rubygems/safe_marshal/reader.rb +325 -0
  451. data/lib/rubygems/safe_marshal/visitors/stream_printer.rb +31 -0
  452. data/lib/rubygems/safe_marshal/visitors/to_ruby.rb +428 -0
  453. data/lib/rubygems/safe_marshal/visitors/visitor.rb +74 -0
  454. data/lib/rubygems/safe_marshal.rb +74 -0
  455. data/lib/rubygems/safe_yaml.rb +14 -26
  456. data/lib/rubygems/security/policies.rb +48 -49
  457. data/lib/rubygems/security/policy.rb +25 -28
  458. data/lib/rubygems/security/signer.rb +16 -7
  459. data/lib/rubygems/security/trust_dir.rb +12 -13
  460. data/lib/rubygems/security.rb +40 -66
  461. data/lib/rubygems/security_option.rb +7 -6
  462. data/lib/rubygems/shellwords.rb +3 -0
  463. data/lib/rubygems/source/git.rb +34 -31
  464. data/lib/rubygems/source/installed.rb +4 -3
  465. data/lib/rubygems/source/local.rb +49 -49
  466. data/lib/rubygems/source/lock.rb +2 -3
  467. data/lib/rubygems/source/specific_file.rb +6 -4
  468. data/lib/rubygems/source/vendor.rb +1 -2
  469. data/lib/rubygems/source.rb +37 -31
  470. data/lib/rubygems/source_list.rb +8 -8
  471. data/lib/rubygems/spec_fetcher.rb +95 -66
  472. data/lib/rubygems/specification.rb +342 -404
  473. data/lib/rubygems/specification_policy.rb +147 -75
  474. data/lib/rubygems/specification_record.rb +212 -0
  475. data/lib/rubygems/stub_specification.rb +56 -30
  476. data/lib/rubygems/target_rbconfig.rb +50 -0
  477. data/lib/rubygems/text.rb +3 -4
  478. data/lib/rubygems/uninstaller.rb +67 -48
  479. data/lib/rubygems/update_suggestion.rb +56 -0
  480. data/lib/rubygems/uri.rb +10 -10
  481. data/lib/rubygems/uri_formatter.rb +2 -2
  482. data/lib/rubygems/user_interaction.rb +50 -40
  483. data/lib/rubygems/util/licenses.rb +310 -39
  484. data/lib/rubygems/util/list.rb +4 -1
  485. data/lib/rubygems/util.rb +19 -20
  486. data/lib/rubygems/validator.rb +15 -14
  487. data/lib/rubygems/vendor/molinillo/.document +1 -0
  488. data/lib/rubygems/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
  489. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +11 -11
  490. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +1 -1
  491. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +1 -1
  492. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +1 -1
  493. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +1 -1
  494. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +1 -1
  495. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +1 -1
  496. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +1 -1
  497. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +1 -1
  498. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +1 -1
  499. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/dependency_graph.rb +3 -3
  500. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/errors.rb +1 -1
  501. data/lib/rubygems/vendor/molinillo/lib/molinillo/gem_metadata.rb +6 -0
  502. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +2 -2
  503. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/modules/ui.rb +1 -1
  504. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/resolution.rb +4 -4
  505. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/resolver.rb +1 -1
  506. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo/state.rb +1 -1
  507. data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/lib/molinillo.rb +2 -2
  508. data/lib/rubygems/vendor/net-http/.document +1 -0
  509. data/lib/rubygems/vendor/net-http/COPYING +56 -0
  510. data/lib/rubygems/vendor/net-http/lib/net/http/exceptions.rb +34 -0
  511. data/lib/rubygems/vendor/net-http/lib/net/http/generic_request.rb +414 -0
  512. data/lib/rubygems/vendor/net-http/lib/net/http/header.rb +981 -0
  513. data/lib/rubygems/vendor/net-http/lib/net/http/proxy_delta.rb +17 -0
  514. data/lib/rubygems/vendor/net-http/lib/net/http/request.rb +88 -0
  515. data/lib/rubygems/vendor/net-http/lib/net/http/requests.rb +430 -0
  516. data/lib/rubygems/vendor/net-http/lib/net/http/response.rb +738 -0
  517. data/lib/rubygems/vendor/net-http/lib/net/http/responses.rb +1174 -0
  518. data/lib/rubygems/vendor/net-http/lib/net/http/status.rb +84 -0
  519. data/lib/rubygems/vendor/net-http/lib/net/http.rb +2580 -0
  520. data/lib/rubygems/vendor/net-http/lib/net/https.rb +23 -0
  521. data/lib/rubygems/vendor/net-protocol/.document +1 -0
  522. data/lib/rubygems/vendor/net-protocol/lib/net/protocol.rb +544 -0
  523. data/lib/rubygems/vendor/optparse/.document +1 -0
  524. data/lib/rubygems/vendor/optparse/COPYING +56 -0
  525. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/ac.rb +16 -0
  526. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/kwargs.rb +8 -3
  527. data/lib/rubygems/vendor/optparse/lib/optparse/uri.rb +7 -0
  528. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/version.rb +9 -0
  529. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse.rb +206 -83
  530. data/lib/rubygems/vendor/resolv/.document +1 -0
  531. data/lib/rubygems/vendor/resolv/COPYING +56 -0
  532. data/lib/rubygems/vendor/resolv/lib/resolv.rb +3455 -0
  533. data/lib/rubygems/vendor/securerandom/.document +1 -0
  534. data/lib/rubygems/vendor/securerandom/COPYING +56 -0
  535. data/lib/rubygems/vendor/securerandom/lib/securerandom.rb +102 -0
  536. data/lib/rubygems/vendor/timeout/.document +1 -0
  537. data/lib/rubygems/vendor/timeout/COPYING +56 -0
  538. data/lib/rubygems/vendor/timeout/lib/timeout.rb +198 -0
  539. data/lib/rubygems/vendor/tsort/.document +1 -0
  540. data/lib/rubygems/vendor/tsort/lib/tsort.rb +455 -0
  541. data/lib/rubygems/vendor/uri/.document +1 -0
  542. data/lib/rubygems/vendor/uri/COPYING +56 -0
  543. data/lib/rubygems/vendor/uri/lib/uri/common.rb +876 -0
  544. data/lib/rubygems/vendor/uri/lib/uri/file.rb +100 -0
  545. data/lib/rubygems/vendor/uri/lib/uri/ftp.rb +267 -0
  546. data/lib/rubygems/vendor/uri/lib/uri/generic.rb +1578 -0
  547. data/lib/rubygems/vendor/uri/lib/uri/http.rb +125 -0
  548. data/lib/rubygems/vendor/uri/lib/uri/https.rb +23 -0
  549. data/lib/rubygems/vendor/uri/lib/uri/ldap.rb +261 -0
  550. data/lib/rubygems/vendor/uri/lib/uri/ldaps.rb +22 -0
  551. data/lib/rubygems/vendor/uri/lib/uri/mailto.rb +293 -0
  552. data/lib/rubygems/vendor/uri/lib/uri/rfc2396_parser.rb +546 -0
  553. data/lib/rubygems/vendor/uri/lib/uri/rfc3986_parser.rb +206 -0
  554. data/lib/rubygems/vendor/uri/lib/uri/version.rb +6 -0
  555. data/lib/rubygems/vendor/uri/lib/uri/ws.rb +83 -0
  556. data/lib/rubygems/vendor/uri/lib/uri/wss.rb +23 -0
  557. data/lib/rubygems/vendor/uri/lib/uri.rb +104 -0
  558. data/{bundler/lib/bundler → lib/rubygems}/vendored_molinillo.rb +0 -1
  559. data/lib/rubygems/vendored_net_http.rb +5 -0
  560. data/lib/rubygems/vendored_optparse.rb +3 -0
  561. data/lib/rubygems/vendored_securerandom.rb +3 -0
  562. data/lib/rubygems/vendored_timeout.rb +5 -0
  563. data/lib/rubygems/vendored_tsort.rb +3 -0
  564. data/lib/rubygems/version.rb +57 -45
  565. data/lib/rubygems/version_option.rb +6 -8
  566. data/lib/rubygems/yaml_serializer.rb +98 -0
  567. data/lib/rubygems.rb +191 -133
  568. data/rubygems-update.gemspec +16 -9
  569. data/setup.rb +12 -9
  570. metadata +233 -307
  571. data/POLICIES.md +0 -100
  572. data/bin/gem +0 -13
  573. data/bundler/lib/bundler/dep_proxy.rb +0 -55
  574. data/bundler/lib/bundler/templates/gems.rb +0 -5
  575. data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +0 -5
  576. data/bundler/lib/bundler/templates/newgem/travis.yml.tt +0 -6
  577. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  578. data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  579. data/bundler/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +0 -154
  580. data/bundler/lib/bundler/version_ranges.rb +0 -122
  581. data/lib/rubygems/indexer.rb +0 -427
  582. data/lib/rubygems/mock_gem_ui.rb +0 -85
  583. data/lib/rubygems/optparse/lib/optparse/uri.rb +0 -7
  584. data/lib/rubygems/optparse.rb +0 -3
  585. data/lib/rubygems/resolver/molinillo/LICENSE +0 -9
  586. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  587. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -88
  588. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
  589. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
  590. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
  591. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
  592. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
  593. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
  594. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
  595. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
  596. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -164
  597. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +0 -255
  598. data/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb +0 -143
  599. data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  600. data/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb +0 -112
  601. data/lib/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb +0 -67
  602. data/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb +0 -839
  603. data/lib/rubygems/resolver/molinillo/lib/molinillo/resolver.rb +0 -46
  604. data/lib/rubygems/resolver/molinillo/lib/molinillo/state.rb +0 -58
  605. data/lib/rubygems/resolver/molinillo/lib/molinillo.rb +0 -11
  606. data/lib/rubygems/resolver/molinillo.rb +0 -2
  607. data/lib/rubygems/tsort/LICENSE.txt +0 -22
  608. data/lib/rubygems/tsort/lib/tsort.rb +0 -454
  609. data/lib/rubygems/tsort.rb +0 -3
  610. data/test/rubygems/alternate_cert.pem +0 -19
  611. data/test/rubygems/alternate_cert_32.pem +0 -19
  612. data/test/rubygems/alternate_key.pem +0 -27
  613. data/test/rubygems/bad_rake.rb +0 -2
  614. data/test/rubygems/ca_cert.pem +0 -77
  615. data/test/rubygems/child_cert.pem +0 -20
  616. data/test/rubygems/child_cert_32.pem +0 -20
  617. data/test/rubygems/child_key.pem +0 -27
  618. data/test/rubygems/client.pem +0 -107
  619. data/test/rubygems/data/excon-0.7.7.gemspec.rz +0 -0
  620. data/test/rubygems/data/gem-private_key.pem +0 -27
  621. data/test/rubygems/data/gem-public_cert.pem +0 -20
  622. data/test/rubygems/data/null-required-ruby-version.gemspec.rz +0 -0
  623. data/test/rubygems/data/null-required-rubygems-version.gemspec.rz +0 -0
  624. data/test/rubygems/data/pry-0.4.7.gemspec.rz +0 -0
  625. data/test/rubygems/encrypted_private_key.pem +0 -30
  626. data/test/rubygems/expired_cert.pem +0 -19
  627. data/test/rubygems/foo/discover.rb +0 -1
  628. data/test/rubygems/future_cert.pem +0 -19
  629. data/test/rubygems/future_cert_32.pem +0 -19
  630. data/test/rubygems/good_rake.rb +0 -2
  631. data/test/rubygems/grandchild_cert.pem +0 -20
  632. data/test/rubygems/grandchild_cert_32.pem +0 -20
  633. data/test/rubygems/grandchild_key.pem +0 -27
  634. data/test/rubygems/helper.rb +0 -1622
  635. data/test/rubygems/installer_test_case.rb +0 -247
  636. data/test/rubygems/invalid_client.pem +0 -49
  637. data/test/rubygems/invalid_issuer_cert.pem +0 -20
  638. data/test/rubygems/invalid_issuer_cert_32.pem +0 -20
  639. data/test/rubygems/invalid_key.pem +0 -27
  640. data/test/rubygems/invalid_signer_cert.pem +0 -19
  641. data/test/rubygems/invalid_signer_cert_32.pem +0 -19
  642. data/test/rubygems/invalidchild_cert.pem +0 -20
  643. data/test/rubygems/invalidchild_cert_32.pem +0 -20
  644. data/test/rubygems/invalidchild_key.pem +0 -27
  645. data/test/rubygems/package/tar_test_case.rb +0 -139
  646. data/test/rubygems/packages/ascii_binder-0.1.10.1.gem +0 -0
  647. data/test/rubygems/packages/ill-formatted-platform-1.0.0.10.gem +0 -0
  648. data/test/rubygems/plugin/exception/rubygems_plugin.rb +0 -3
  649. data/test/rubygems/plugin/load/rubygems_plugin.rb +0 -4
  650. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +0 -3
  651. data/test/rubygems/private3072_key.pem +0 -40
  652. data/test/rubygems/private_ec_key.pem +0 -9
  653. data/test/rubygems/private_key.pem +0 -27
  654. data/test/rubygems/public3072_cert.pem +0 -25
  655. data/test/rubygems/public_cert.pem +0 -20
  656. data/test/rubygems/public_cert_32.pem +0 -19
  657. data/test/rubygems/public_key.pem +0 -9
  658. data/test/rubygems/rubygems/commands/crash_command.rb +0 -4
  659. data/test/rubygems/rubygems_plugin.rb +0 -23
  660. data/test/rubygems/sff/discover.rb +0 -1
  661. data/test/rubygems/simple_gem.rb +0 -67
  662. data/test/rubygems/specifications/bar-0.0.2.gemspec +0 -7
  663. data/test/rubygems/specifications/foo-0.0.1-x86-mswin32.gemspec +0 -0
  664. data/test/rubygems/specifications/rubyforge-0.0.1.gemspec +0 -12
  665. data/test/rubygems/ssl_cert.pem +0 -80
  666. data/test/rubygems/ssl_key.pem +0 -27
  667. data/test/rubygems/test_bundled_ca.rb +0 -60
  668. data/test/rubygems/test_config.rb +0 -27
  669. data/test/rubygems/test_deprecate.rb +0 -157
  670. data/test/rubygems/test_exit.rb +0 -11
  671. data/test/rubygems/test_gem.rb +0 -2112
  672. data/test/rubygems/test_gem_available_set.rb +0 -129
  673. data/test/rubygems/test_gem_bundler_version_finder.rb +0 -125
  674. data/test/rubygems/test_gem_command.rb +0 -400
  675. data/test/rubygems/test_gem_command_manager.rb +0 -334
  676. data/test/rubygems/test_gem_commands_build_command.rb +0 -727
  677. data/test/rubygems/test_gem_commands_cert_command.rb +0 -867
  678. data/test/rubygems/test_gem_commands_check_command.rb +0 -67
  679. data/test/rubygems/test_gem_commands_cleanup_command.rb +0 -291
  680. data/test/rubygems/test_gem_commands_contents_command.rb +0 -270
  681. data/test/rubygems/test_gem_commands_dependency_command.rb +0 -227
  682. data/test/rubygems/test_gem_commands_environment_command.rb +0 -167
  683. data/test/rubygems/test_gem_commands_fetch_command.rb +0 -257
  684. data/test/rubygems/test_gem_commands_generate_index_command.rb +0 -80
  685. data/test/rubygems/test_gem_commands_help_command.rb +0 -93
  686. data/test/rubygems/test_gem_commands_info_command.rb +0 -43
  687. data/test/rubygems/test_gem_commands_install_command.rb +0 -1553
  688. data/test/rubygems/test_gem_commands_list_command.rb +0 -32
  689. data/test/rubygems/test_gem_commands_lock_command.rb +0 -66
  690. data/test/rubygems/test_gem_commands_mirror.rb +0 -19
  691. data/test/rubygems/test_gem_commands_open_command.rb +0 -97
  692. data/test/rubygems/test_gem_commands_outdated_command.rb +0 -49
  693. data/test/rubygems/test_gem_commands_owner_command.rb +0 -326
  694. data/test/rubygems/test_gem_commands_pristine_command.rb +0 -659
  695. data/test/rubygems/test_gem_commands_push_command.rb +0 -477
  696. data/test/rubygems/test_gem_commands_query_command.rb +0 -857
  697. data/test/rubygems/test_gem_commands_search_command.rb +0 -15
  698. data/test/rubygems/test_gem_commands_server_command.rb +0 -19
  699. data/test/rubygems/test_gem_commands_setup_command.rb +0 -447
  700. data/test/rubygems/test_gem_commands_signin_command.rb +0 -219
  701. data/test/rubygems/test_gem_commands_signout_command.rb +0 -30
  702. data/test/rubygems/test_gem_commands_sources_command.rb +0 -534
  703. data/test/rubygems/test_gem_commands_specification_command.rb +0 -276
  704. data/test/rubygems/test_gem_commands_stale_command.rb +0 -42
  705. data/test/rubygems/test_gem_commands_uninstall_command.rb +0 -504
  706. data/test/rubygems/test_gem_commands_unpack_command.rb +0 -223
  707. data/test/rubygems/test_gem_commands_update_command.rb +0 -835
  708. data/test/rubygems/test_gem_commands_which_command.rb +0 -84
  709. data/test/rubygems/test_gem_commands_yank_command.rb +0 -180
  710. data/test/rubygems/test_gem_config_file.rb +0 -504
  711. data/test/rubygems/test_gem_dependency.rb +0 -395
  712. data/test/rubygems/test_gem_dependency_installer.rb +0 -1155
  713. data/test/rubygems/test_gem_dependency_list.rb +0 -264
  714. data/test/rubygems/test_gem_dependency_resolution_error.rb +0 -26
  715. data/test/rubygems/test_gem_doctor.rb +0 -194
  716. data/test/rubygems/test_gem_ext_builder.rb +0 -338
  717. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/.gitignore +0 -1
  718. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock +0 -243
  719. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml +0 -10
  720. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb +0 -21
  721. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec +0 -10
  722. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/src/lib.rs +0 -27
  723. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/.gitignore +0 -1
  724. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +0 -243
  725. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +0 -10
  726. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb +0 -21
  727. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/rust_ruby_example.gemspec +0 -8
  728. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs +0 -39
  729. data/test/rubygems/test_gem_ext_cargo_builder.rb +0 -178
  730. data/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb +0 -33
  731. data/test/rubygems/test_gem_ext_cargo_builder_unit.rb +0 -75
  732. data/test/rubygems/test_gem_ext_cmake_builder.rb +0 -83
  733. data/test/rubygems/test_gem_ext_configure_builder.rb +0 -79
  734. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +0 -230
  735. data/test/rubygems/test_gem_ext_rake_builder.rb +0 -112
  736. data/test/rubygems/test_gem_gem_runner.rb +0 -113
  737. data/test/rubygems/test_gem_gemcutter_utilities.rb +0 -272
  738. data/test/rubygems/test_gem_impossible_dependencies_error.rb +0 -59
  739. data/test/rubygems/test_gem_indexer.rb +0 -361
  740. data/test/rubygems/test_gem_install_update_options.rb +0 -207
  741. data/test/rubygems/test_gem_installer.rb +0 -2394
  742. data/test/rubygems/test_gem_local_remote_options.rb +0 -132
  743. data/test/rubygems/test_gem_name_tuple.rb +0 -42
  744. data/test/rubygems/test_gem_package.rb +0 -1178
  745. data/test/rubygems/test_gem_package_old.rb +0 -90
  746. data/test/rubygems/test_gem_package_tar_header.rb +0 -225
  747. data/test/rubygems/test_gem_package_tar_reader.rb +0 -87
  748. data/test/rubygems/test_gem_package_tar_reader_entry.rb +0 -152
  749. data/test/rubygems/test_gem_package_tar_writer.rb +0 -330
  750. data/test/rubygems/test_gem_package_task.rb +0 -117
  751. data/test/rubygems/test_gem_path_support.rb +0 -138
  752. data/test/rubygems/test_gem_platform.rb +0 -391
  753. data/test/rubygems/test_gem_rdoc.rb +0 -136
  754. data/test/rubygems/test_gem_remote_fetcher.rb +0 -1226
  755. data/test/rubygems/test_gem_request.rb +0 -541
  756. data/test/rubygems/test_gem_request_connection_pools.rb +0 -150
  757. data/test/rubygems/test_gem_request_set.rb +0 -671
  758. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +0 -847
  759. data/test/rubygems/test_gem_request_set_lockfile.rb +0 -468
  760. data/test/rubygems/test_gem_request_set_lockfile_parser.rb +0 -543
  761. data/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb +0 -306
  762. data/test/rubygems/test_gem_requirement.rb +0 -498
  763. data/test/rubygems/test_gem_resolver.rb +0 -791
  764. data/test/rubygems/test_gem_resolver_activation_request.rb +0 -42
  765. data/test/rubygems/test_gem_resolver_api_set.rb +0 -209
  766. data/test/rubygems/test_gem_resolver_api_specification.rb +0 -166
  767. data/test/rubygems/test_gem_resolver_best_set.rb +0 -158
  768. data/test/rubygems/test_gem_resolver_composed_set.rb +0 -43
  769. data/test/rubygems/test_gem_resolver_conflict.rb +0 -81
  770. data/test/rubygems/test_gem_resolver_dependency_request.rb +0 -82
  771. data/test/rubygems/test_gem_resolver_git_set.rb +0 -187
  772. data/test/rubygems/test_gem_resolver_git_specification.rb +0 -113
  773. data/test/rubygems/test_gem_resolver_index_set.rb +0 -87
  774. data/test/rubygems/test_gem_resolver_index_specification.rb +0 -92
  775. data/test/rubygems/test_gem_resolver_installed_specification.rb +0 -46
  776. data/test/rubygems/test_gem_resolver_installer_set.rb +0 -275
  777. data/test/rubygems/test_gem_resolver_local_specification.rb +0 -43
  778. data/test/rubygems/test_gem_resolver_lock_set.rb +0 -61
  779. data/test/rubygems/test_gem_resolver_lock_specification.rb +0 -97
  780. data/test/rubygems/test_gem_resolver_requirement_list.rb +0 -18
  781. data/test/rubygems/test_gem_resolver_specification.rb +0 -62
  782. data/test/rubygems/test_gem_resolver_vendor_set.rb +0 -81
  783. data/test/rubygems/test_gem_resolver_vendor_specification.rb +0 -81
  784. data/test/rubygems/test_gem_security.rb +0 -340
  785. data/test/rubygems/test_gem_security_policy.rb +0 -535
  786. data/test/rubygems/test_gem_security_signer.rb +0 -217
  787. data/test/rubygems/test_gem_security_trust_dir.rb +0 -98
  788. data/test/rubygems/test_gem_silent_ui.rb +0 -116
  789. data/test/rubygems/test_gem_source.rb +0 -253
  790. data/test/rubygems/test_gem_source_fetch_problem.rb +0 -36
  791. data/test/rubygems/test_gem_source_git.rb +0 -303
  792. data/test/rubygems/test_gem_source_installed.rb +0 -34
  793. data/test/rubygems/test_gem_source_list.rb +0 -118
  794. data/test/rubygems/test_gem_source_local.rb +0 -106
  795. data/test/rubygems/test_gem_source_lock.rb +0 -112
  796. data/test/rubygems/test_gem_source_specific_file.rb +0 -75
  797. data/test/rubygems/test_gem_source_subpath_problem.rb +0 -49
  798. data/test/rubygems/test_gem_source_vendor.rb +0 -29
  799. data/test/rubygems/test_gem_spec_fetcher.rb +0 -337
  800. data/test/rubygems/test_gem_specification.rb +0 -3756
  801. data/test/rubygems/test_gem_stream_ui.rb +0 -224
  802. data/test/rubygems/test_gem_stub_specification.rb +0 -277
  803. data/test/rubygems/test_gem_text.rb +0 -102
  804. data/test/rubygems/test_gem_uninstaller.rb +0 -674
  805. data/test/rubygems/test_gem_unsatisfiable_dependency_error.rb +0 -30
  806. data/test/rubygems/test_gem_uri.rb +0 -39
  807. data/test/rubygems/test_gem_uri_formatter.rb +0 -26
  808. data/test/rubygems/test_gem_util.rb +0 -90
  809. data/test/rubygems/test_gem_validator.rb +0 -42
  810. data/test/rubygems/test_gem_version.rb +0 -295
  811. data/test/rubygems/test_gem_version_option.rb +0 -164
  812. data/test/rubygems/test_kernel.rb +0 -129
  813. data/test/rubygems/test_project_sanity.rb +0 -20
  814. data/test/rubygems/test_remote_fetch_error.rb +0 -19
  815. data/test/rubygems/test_require.rb +0 -719
  816. data/test/rubygems/test_rubygems.rb +0 -74
  817. data/test/rubygems/utilities.rb +0 -371
  818. data/test/rubygems/wrong_key_cert.pem +0 -19
  819. data/test/rubygems/wrong_key_cert_32.pem +0 -19
  820. data/test/test_changelog_generator.rb +0 -17
  821. /data/{lib/rubygems/optparse → bundler/lib/bundler/vendor/connection_pool}/.document +0 -0
  822. /data/{lib/rubygems/tsort → bundler/lib/bundler/vendor/fileutils}/.document +0 -0
  823. /data/{lib/rubygems/optparse → bundler/lib/bundler/vendor/fileutils}/COPYING +0 -0
  824. /data/{MAINTAINERS.txt → doc/MAINTAINERS.txt} +0 -0
  825. /data/{UPGRADING.md → doc/rubygems/UPGRADING.md} +0 -0
  826. /data/{bundler/lib/bundler → lib/rubygems}/vendor/molinillo/LICENSE +0 -0
  827. /data/{bundler/lib/bundler/vendor/fileutils → lib/rubygems/vendor/net-protocol}/LICENSE.txt +0 -0
  828. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optionparser.rb +0 -0
  829. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/date.rb +0 -0
  830. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/shellwords.rb +0 -0
  831. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/time.rb +0 -0
  832. /data/{bundler/lib/bundler/vendor/uri → lib/rubygems/vendor/tsort}/LICENSE.txt +0 -0
@@ -0,0 +1,2580 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # = net/http.rb
4
+ #
5
+ # Copyright (c) 1999-2007 Yukihiro Matsumoto
6
+ # Copyright (c) 1999-2007 Minero Aoki
7
+ # Copyright (c) 2001 GOTOU Yuuzou
8
+ #
9
+ # Written and maintained by Minero Aoki <aamine@loveruby.net>.
10
+ # HTTPS support added by GOTOU Yuuzou <gotoyuzo@notwork.org>.
11
+ #
12
+ # This file is derived from "http-access.rb".
13
+ #
14
+ # Documented by Minero Aoki; converted to RDoc by William Webber.
15
+ #
16
+ # This program is free software. You can re-distribute and/or
17
+ # modify this program under the same terms of ruby itself ---
18
+ # Ruby Distribution License or GNU General Public License.
19
+ #
20
+ # See Gem::Net::HTTP for an overview and examples.
21
+ #
22
+
23
+ require_relative '../../../net-protocol/lib/net/protocol'
24
+ require_relative '../../../uri/lib/uri'
25
+ require_relative '../../../resolv/lib/resolv'
26
+ autoload :OpenSSL, 'openssl'
27
+
28
+ module Gem::Net #:nodoc:
29
+
30
+ # :stopdoc:
31
+ class HTTPBadResponse < StandardError; end
32
+ class HTTPHeaderSyntaxError < StandardError; end
33
+ # :startdoc:
34
+
35
+ # \Class \Gem::Net::HTTP provides a rich library that implements the client
36
+ # in a client-server model that uses the \HTTP request-response protocol.
37
+ # For information about \HTTP, see:
38
+ #
39
+ # - {Hypertext Transfer Protocol}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol].
40
+ # - {Technical overview}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Technical_overview].
41
+ #
42
+ # == About the Examples
43
+ #
44
+ # :include: doc/net-http/examples.rdoc
45
+ #
46
+ # == Strategies
47
+ #
48
+ # - If you will make only a few GET requests,
49
+ # consider using {OpenURI}[https://docs.ruby-lang.org/en/master/OpenURI.html].
50
+ # - If you will make only a few requests of all kinds,
51
+ # consider using the various singleton convenience methods in this class.
52
+ # Each of the following methods automatically starts and finishes
53
+ # a {session}[rdoc-ref:Gem::Net::HTTP@Sessions] that sends a single request:
54
+ #
55
+ # # Return string response body.
56
+ # Gem::Net::HTTP.get(hostname, path)
57
+ # Gem::Net::HTTP.get(uri)
58
+ #
59
+ # # Write string response body to $stdout.
60
+ # Gem::Net::HTTP.get_print(hostname, path)
61
+ # Gem::Net::HTTP.get_print(uri)
62
+ #
63
+ # # Return response as Gem::Net::HTTPResponse object.
64
+ # Gem::Net::HTTP.get_response(hostname, path)
65
+ # Gem::Net::HTTP.get_response(uri)
66
+ # data = '{"title": "foo", "body": "bar", "userId": 1}'
67
+ # Gem::Net::HTTP.post(uri, data)
68
+ # params = {title: 'foo', body: 'bar', userId: 1}
69
+ # Gem::Net::HTTP.post_form(uri, params)
70
+ # data = '{"title": "foo", "body": "bar", "userId": 1}'
71
+ # Gem::Net::HTTP.put(uri, data)
72
+ #
73
+ # - If performance is important, consider using sessions, which lower request overhead.
74
+ # This {session}[rdoc-ref:Gem::Net::HTTP@Sessions] has multiple requests for
75
+ # {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods]
76
+ # and {WebDAV methods}[https://en.wikipedia.org/wiki/WebDAV#Implementation]:
77
+ #
78
+ # Gem::Net::HTTP.start(hostname) do |http|
79
+ # # Session started automatically before block execution.
80
+ # http.get(path)
81
+ # http.head(path)
82
+ # body = 'Some text'
83
+ # http.post(path, body) # Can also have a block.
84
+ # http.put(path, body)
85
+ # http.delete(path)
86
+ # http.options(path)
87
+ # http.trace(path)
88
+ # http.patch(path, body) # Can also have a block.
89
+ # http.copy(path)
90
+ # http.lock(path, body)
91
+ # http.mkcol(path, body)
92
+ # http.move(path)
93
+ # http.propfind(path, body)
94
+ # http.proppatch(path, body)
95
+ # http.unlock(path, body)
96
+ # # Session finished automatically at block exit.
97
+ # end
98
+ #
99
+ # The methods cited above are convenience methods that, via their few arguments,
100
+ # allow minimal control over the requests.
101
+ # For greater control, consider using {request objects}[rdoc-ref:Gem::Net::HTTPRequest].
102
+ #
103
+ # == URIs
104
+ #
105
+ # On the internet, a URI
106
+ # ({Universal Resource Identifier}[https://en.wikipedia.org/wiki/Uniform_Resource_Identifier])
107
+ # is a string that identifies a particular resource.
108
+ # It consists of some or all of: scheme, hostname, path, query, and fragment;
109
+ # see {URI syntax}[https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax].
110
+ #
111
+ # A Ruby {Gem::URI::Generic}[https://docs.ruby-lang.org/en/master/Gem/URI/Generic.html] object
112
+ # represents an internet URI.
113
+ # It provides, among others, methods
114
+ # +scheme+, +hostname+, +path+, +query+, and +fragment+.
115
+ #
116
+ # === Schemes
117
+ #
118
+ # An internet \Gem::URI has
119
+ # a {scheme}[https://en.wikipedia.org/wiki/List_of_URI_schemes].
120
+ #
121
+ # The two schemes supported in \Gem::Net::HTTP are <tt>'https'</tt> and <tt>'http'</tt>:
122
+ #
123
+ # uri.scheme # => "https"
124
+ # Gem::URI('http://example.com').scheme # => "http"
125
+ #
126
+ # === Hostnames
127
+ #
128
+ # A hostname identifies a server (host) to which requests may be sent:
129
+ #
130
+ # hostname = uri.hostname # => "jsonplaceholder.typicode.com"
131
+ # Gem::Net::HTTP.start(hostname) do |http|
132
+ # # Some HTTP stuff.
133
+ # end
134
+ #
135
+ # === Paths
136
+ #
137
+ # A host-specific path identifies a resource on the host:
138
+ #
139
+ # _uri = uri.dup
140
+ # _uri.path = '/todos/1'
141
+ # hostname = _uri.hostname
142
+ # path = _uri.path
143
+ # Gem::Net::HTTP.get(hostname, path)
144
+ #
145
+ # === Queries
146
+ #
147
+ # A host-specific query adds name/value pairs to the URI:
148
+ #
149
+ # _uri = uri.dup
150
+ # params = {userId: 1, completed: false}
151
+ # _uri.query = Gem::URI.encode_www_form(params)
152
+ # _uri # => #<Gem::URI::HTTPS https://jsonplaceholder.typicode.com?userId=1&completed=false>
153
+ # Gem::Net::HTTP.get(_uri)
154
+ #
155
+ # === Fragments
156
+ #
157
+ # A {URI fragment}[https://en.wikipedia.org/wiki/URI_fragment] has no effect
158
+ # in \Gem::Net::HTTP;
159
+ # the same data is returned, regardless of whether a fragment is included.
160
+ #
161
+ # == Request Headers
162
+ #
163
+ # Request headers may be used to pass additional information to the host,
164
+ # similar to arguments passed in a method call;
165
+ # each header is a name/value pair.
166
+ #
167
+ # Each of the \Gem::Net::HTTP methods that sends a request to the host
168
+ # has optional argument +headers+,
169
+ # where the headers are expressed as a hash of field-name/value pairs:
170
+ #
171
+ # headers = {Accept: 'application/json', Connection: 'Keep-Alive'}
172
+ # Gem::Net::HTTP.get(uri, headers)
173
+ #
174
+ # See lists of both standard request fields and common request fields at
175
+ # {Request Fields}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields].
176
+ # A host may also accept other custom fields.
177
+ #
178
+ # == \HTTP Sessions
179
+ #
180
+ # A _session_ is a connection between a server (host) and a client that:
181
+ #
182
+ # - Is begun by instance method Gem::Net::HTTP#start.
183
+ # - May contain any number of requests.
184
+ # - Is ended by instance method Gem::Net::HTTP#finish.
185
+ #
186
+ # See example sessions at {Strategies}[rdoc-ref:Gem::Net::HTTP@Strategies].
187
+ #
188
+ # === Session Using \Gem::Net::HTTP.start
189
+ #
190
+ # If you have many requests to make to a single host (and port),
191
+ # consider using singleton method Gem::Net::HTTP.start with a block;
192
+ # the method handles the session automatically by:
193
+ #
194
+ # - Calling #start before block execution.
195
+ # - Executing the block.
196
+ # - Calling #finish after block execution.
197
+ #
198
+ # In the block, you can use these instance methods,
199
+ # each of which that sends a single request:
200
+ #
201
+ # - {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods]:
202
+ #
203
+ # - #get, #request_get: GET.
204
+ # - #head, #request_head: HEAD.
205
+ # - #post, #request_post: POST.
206
+ # - #delete: DELETE.
207
+ # - #options: OPTIONS.
208
+ # - #trace: TRACE.
209
+ # - #patch: PATCH.
210
+ #
211
+ # - {WebDAV methods}[https://en.wikipedia.org/wiki/WebDAV#Implementation]:
212
+ #
213
+ # - #copy: COPY.
214
+ # - #lock: LOCK.
215
+ # - #mkcol: MKCOL.
216
+ # - #move: MOVE.
217
+ # - #propfind: PROPFIND.
218
+ # - #proppatch: PROPPATCH.
219
+ # - #unlock: UNLOCK.
220
+ #
221
+ # === Session Using \Gem::Net::HTTP.start and \Gem::Net::HTTP.finish
222
+ #
223
+ # You can manage a session manually using methods #start and #finish:
224
+ #
225
+ # http = Gem::Net::HTTP.new(hostname)
226
+ # http.start
227
+ # http.get('/todos/1')
228
+ # http.get('/todos/2')
229
+ # http.delete('/posts/1')
230
+ # http.finish # Needed to free resources.
231
+ #
232
+ # === Single-Request Session
233
+ #
234
+ # Certain convenience methods automatically handle a session by:
235
+ #
236
+ # - Creating an \HTTP object
237
+ # - Starting a session.
238
+ # - Sending a single request.
239
+ # - Finishing the session.
240
+ # - Destroying the object.
241
+ #
242
+ # Such methods that send GET requests:
243
+ #
244
+ # - ::get: Returns the string response body.
245
+ # - ::get_print: Writes the string response body to $stdout.
246
+ # - ::get_response: Returns a Gem::Net::HTTPResponse object.
247
+ #
248
+ # Such methods that send POST requests:
249
+ #
250
+ # - ::post: Posts data to the host.
251
+ # - ::post_form: Posts form data to the host.
252
+ #
253
+ # == \HTTP Requests and Responses
254
+ #
255
+ # Many of the methods above are convenience methods,
256
+ # each of which sends a request and returns a string
257
+ # without directly using \Gem::Net::HTTPRequest and \Gem::Net::HTTPResponse objects.
258
+ #
259
+ # You can, however, directly create a request object, send the request,
260
+ # and retrieve the response object; see:
261
+ #
262
+ # - Gem::Net::HTTPRequest.
263
+ # - Gem::Net::HTTPResponse.
264
+ #
265
+ # == Following Redirection
266
+ #
267
+ # Each returned response is an instance of a subclass of Gem::Net::HTTPResponse.
268
+ # See the {response class hierarchy}[rdoc-ref:Gem::Net::HTTPResponse@Response+Subclasses].
269
+ #
270
+ # In particular, class Gem::Net::HTTPRedirection is the parent
271
+ # of all redirection classes.
272
+ # This allows you to craft a case statement to handle redirections properly:
273
+ #
274
+ # def fetch(uri, limit = 10)
275
+ # # You should choose a better exception.
276
+ # raise ArgumentError, 'Too many HTTP redirects' if limit == 0
277
+ #
278
+ # res = Gem::Net::HTTP.get_response(Gem::URI(uri))
279
+ # case res
280
+ # when Gem::Net::HTTPSuccess # Any success class.
281
+ # res
282
+ # when Gem::Net::HTTPRedirection # Any redirection class.
283
+ # location = res['Location']
284
+ # warn "Redirected to #{location}"
285
+ # fetch(location, limit - 1)
286
+ # else # Any other class.
287
+ # res.value
288
+ # end
289
+ # end
290
+ #
291
+ # fetch(uri)
292
+ #
293
+ # == Basic Authentication
294
+ #
295
+ # Basic authentication is performed according to
296
+ # {RFC2617}[http://www.ietf.org/rfc/rfc2617.txt]:
297
+ #
298
+ # req = Gem::Net::HTTP::Get.new(uri)
299
+ # req.basic_auth('user', 'pass')
300
+ # res = Gem::Net::HTTP.start(hostname) do |http|
301
+ # http.request(req)
302
+ # end
303
+ #
304
+ # == Streaming Response Bodies
305
+ #
306
+ # By default \Gem::Net::HTTP reads an entire response into memory. If you are
307
+ # handling large files or wish to implement a progress bar you can instead
308
+ # stream the body directly to an IO.
309
+ #
310
+ # Gem::Net::HTTP.start(hostname) do |http|
311
+ # req = Gem::Net::HTTP::Get.new(uri)
312
+ # http.request(req) do |res|
313
+ # open('t.tmp', 'w') do |f|
314
+ # res.read_body do |chunk|
315
+ # f.write chunk
316
+ # end
317
+ # end
318
+ # end
319
+ # end
320
+ #
321
+ # == HTTPS
322
+ #
323
+ # HTTPS is enabled for an \HTTP connection by Gem::Net::HTTP#use_ssl=:
324
+ #
325
+ # Gem::Net::HTTP.start(hostname, :use_ssl => true) do |http|
326
+ # req = Gem::Net::HTTP::Get.new(uri)
327
+ # res = http.request(req)
328
+ # end
329
+ #
330
+ # Or if you simply want to make a GET request, you may pass in a URI
331
+ # object that has an \HTTPS URL. \Gem::Net::HTTP automatically turns on TLS
332
+ # verification if the URI object has a 'https' :URI scheme:
333
+ #
334
+ # uri # => #<Gem::URI::HTTPS https://jsonplaceholder.typicode.com/>
335
+ # Gem::Net::HTTP.get(uri)
336
+ #
337
+ # == Proxy Server
338
+ #
339
+ # An \HTTP object can have
340
+ # a {proxy server}[https://en.wikipedia.org/wiki/Proxy_server].
341
+ #
342
+ # You can create an \HTTP object with a proxy server
343
+ # using method Gem::Net::HTTP.new or method Gem::Net::HTTP.start.
344
+ #
345
+ # The proxy may be defined either by argument +p_addr+
346
+ # or by environment variable <tt>'http_proxy'</tt>.
347
+ #
348
+ # === Proxy Using Argument +p_addr+ as a \String
349
+ #
350
+ # When argument +p_addr+ is a string hostname,
351
+ # the returned +http+ has the given host as its proxy:
352
+ #
353
+ # http = Gem::Net::HTTP.new(hostname, nil, 'proxy.example')
354
+ # http.proxy? # => true
355
+ # http.proxy_from_env? # => false
356
+ # http.proxy_address # => "proxy.example"
357
+ # # These use default values.
358
+ # http.proxy_port # => 80
359
+ # http.proxy_user # => nil
360
+ # http.proxy_pass # => nil
361
+ #
362
+ # The port, username, and password for the proxy may also be given:
363
+ #
364
+ # http = Gem::Net::HTTP.new(hostname, nil, 'proxy.example', 8000, 'pname', 'ppass')
365
+ # # => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>
366
+ # http.proxy? # => true
367
+ # http.proxy_from_env? # => false
368
+ # http.proxy_address # => "proxy.example"
369
+ # http.proxy_port # => 8000
370
+ # http.proxy_user # => "pname"
371
+ # http.proxy_pass # => "ppass"
372
+ #
373
+ # === Proxy Using '<tt>ENV['http_proxy']</tt>'
374
+ #
375
+ # When environment variable <tt>'http_proxy'</tt>
376
+ # is set to a \Gem::URI string,
377
+ # the returned +http+ will have the server at that URI as its proxy;
378
+ # note that the \Gem::URI string must have a protocol
379
+ # such as <tt>'http'</tt> or <tt>'https'</tt>:
380
+ #
381
+ # ENV['http_proxy'] = 'http://example.com'
382
+ # http = Gem::Net::HTTP.new(hostname)
383
+ # http.proxy? # => true
384
+ # http.proxy_from_env? # => true
385
+ # http.proxy_address # => "example.com"
386
+ # # These use default values.
387
+ # http.proxy_port # => 80
388
+ # http.proxy_user # => nil
389
+ # http.proxy_pass # => nil
390
+ #
391
+ # The \Gem::URI string may include proxy username, password, and port number:
392
+ #
393
+ # ENV['http_proxy'] = 'http://pname:ppass@example.com:8000'
394
+ # http = Gem::Net::HTTP.new(hostname)
395
+ # http.proxy? # => true
396
+ # http.proxy_from_env? # => true
397
+ # http.proxy_address # => "example.com"
398
+ # http.proxy_port # => 8000
399
+ # http.proxy_user # => "pname"
400
+ # http.proxy_pass # => "ppass"
401
+ #
402
+ # === Filtering Proxies
403
+ #
404
+ # With method Gem::Net::HTTP.new (but not Gem::Net::HTTP.start),
405
+ # you can use argument +p_no_proxy+ to filter proxies:
406
+ #
407
+ # - Reject a certain address:
408
+ #
409
+ # http = Gem::Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
410
+ # http.proxy_address # => nil
411
+ #
412
+ # - Reject certain domains or subdomains:
413
+ #
414
+ # http = Gem::Net::HTTP.new('example.com', nil, 'my.proxy.example', 8000, 'pname', 'ppass', 'proxy.example')
415
+ # http.proxy_address # => nil
416
+ #
417
+ # - Reject certain addresses and port combinations:
418
+ #
419
+ # http = Gem::Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:1234')
420
+ # http.proxy_address # => "proxy.example"
421
+ #
422
+ # http = Gem::Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'proxy.example:8000')
423
+ # http.proxy_address # => nil
424
+ #
425
+ # - Reject a list of the types above delimited using a comma:
426
+ #
427
+ # http = Gem::Net::HTTP.new('example.com', nil, 'proxy.example', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
428
+ # http.proxy_address # => nil
429
+ #
430
+ # http = Gem::Net::HTTP.new('example.com', nil, 'my.proxy', 8000, 'pname', 'ppass', 'my.proxy,proxy.example:8000')
431
+ # http.proxy_address # => nil
432
+ #
433
+ # == Compression and Decompression
434
+ #
435
+ # \Gem::Net::HTTP does not compress the body of a request before sending.
436
+ #
437
+ # By default, \Gem::Net::HTTP adds header <tt>'Accept-Encoding'</tt>
438
+ # to a new {request object}[rdoc-ref:Gem::Net::HTTPRequest]:
439
+ #
440
+ # Gem::Net::HTTP::Get.new(uri)['Accept-Encoding']
441
+ # # => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
442
+ #
443
+ # This requests the server to zip-encode the response body if there is one;
444
+ # the server is not required to do so.
445
+ #
446
+ # \Gem::Net::HTTP does not automatically decompress a response body
447
+ # if the response has header <tt>'Content-Range'</tt>.
448
+ #
449
+ # Otherwise decompression (or not) depends on the value of header
450
+ # {Content-Encoding}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#content-encoding-response-header]:
451
+ #
452
+ # - <tt>'deflate'</tt>, <tt>'gzip'</tt>, or <tt>'x-gzip'</tt>:
453
+ # decompresses the body and deletes the header.
454
+ # - <tt>'none'</tt> or <tt>'identity'</tt>:
455
+ # does not decompress the body, but deletes the header.
456
+ # - Any other value:
457
+ # leaves the body and header unchanged.
458
+ #
459
+ # == What's Here
460
+ #
461
+ # First, what's elsewhere. Class Gem::Net::HTTP:
462
+ #
463
+ # - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html#class-Object-label-What-27s+Here].
464
+ #
465
+ # This is a categorized summary of methods and attributes.
466
+ #
467
+ # === \Gem::Net::HTTP Objects
468
+ #
469
+ # - {::new}[rdoc-ref:Gem::Net::HTTP.new]:
470
+ # Creates a new instance.
471
+ # - {#inspect}[rdoc-ref:Gem::Net::HTTP#inspect]:
472
+ # Returns a string representation of +self+.
473
+ #
474
+ # === Sessions
475
+ #
476
+ # - {::start}[rdoc-ref:Gem::Net::HTTP.start]:
477
+ # Begins a new session in a new \Gem::Net::HTTP object.
478
+ # - {#started?}[rdoc-ref:Gem::Net::HTTP#started?]
479
+ # (aliased as {#active?}[rdoc-ref:Gem::Net::HTTP#active?]):
480
+ # Returns whether in a session.
481
+ # - {#finish}[rdoc-ref:Gem::Net::HTTP#finish]:
482
+ # Ends an active session.
483
+ # - {#start}[rdoc-ref:Gem::Net::HTTP#start]:
484
+ # Begins a new session in an existing \Gem::Net::HTTP object (+self+).
485
+ #
486
+ # === Connections
487
+ #
488
+ # - {:continue_timeout}[rdoc-ref:Gem::Net::HTTP#continue_timeout]:
489
+ # Returns the continue timeout.
490
+ # - {#continue_timeout=}[rdoc-ref:Gem::Net::HTTP#continue_timeout=]:
491
+ # Sets the continue timeout seconds.
492
+ # - {:keep_alive_timeout}[rdoc-ref:Gem::Net::HTTP#keep_alive_timeout]:
493
+ # Returns the keep-alive timeout.
494
+ # - {:keep_alive_timeout=}[rdoc-ref:Gem::Net::HTTP#keep_alive_timeout=]:
495
+ # Sets the keep-alive timeout.
496
+ # - {:max_retries}[rdoc-ref:Gem::Net::HTTP#max_retries]:
497
+ # Returns the maximum retries.
498
+ # - {#max_retries=}[rdoc-ref:Gem::Net::HTTP#max_retries=]:
499
+ # Sets the maximum retries.
500
+ # - {:open_timeout}[rdoc-ref:Gem::Net::HTTP#open_timeout]:
501
+ # Returns the open timeout.
502
+ # - {:open_timeout=}[rdoc-ref:Gem::Net::HTTP#open_timeout=]:
503
+ # Sets the open timeout.
504
+ # - {:read_timeout}[rdoc-ref:Gem::Net::HTTP#read_timeout]:
505
+ # Returns the open timeout.
506
+ # - {:read_timeout=}[rdoc-ref:Gem::Net::HTTP#read_timeout=]:
507
+ # Sets the read timeout.
508
+ # - {:ssl_timeout}[rdoc-ref:Gem::Net::HTTP#ssl_timeout]:
509
+ # Returns the ssl timeout.
510
+ # - {:ssl_timeout=}[rdoc-ref:Gem::Net::HTTP#ssl_timeout=]:
511
+ # Sets the ssl timeout.
512
+ # - {:write_timeout}[rdoc-ref:Gem::Net::HTTP#write_timeout]:
513
+ # Returns the write timeout.
514
+ # - {write_timeout=}[rdoc-ref:Gem::Net::HTTP#write_timeout=]:
515
+ # Sets the write timeout.
516
+ #
517
+ # === Requests
518
+ #
519
+ # - {::get}[rdoc-ref:Gem::Net::HTTP.get]:
520
+ # Sends a GET request and returns the string response body.
521
+ # - {::get_print}[rdoc-ref:Gem::Net::HTTP.get_print]:
522
+ # Sends a GET request and write the string response body to $stdout.
523
+ # - {::get_response}[rdoc-ref:Gem::Net::HTTP.get_response]:
524
+ # Sends a GET request and returns a response object.
525
+ # - {::post_form}[rdoc-ref:Gem::Net::HTTP.post_form]:
526
+ # Sends a POST request with form data and returns a response object.
527
+ # - {::post}[rdoc-ref:Gem::Net::HTTP.post]:
528
+ # Sends a POST request with data and returns a response object.
529
+ # - {::put}[rdoc-ref:Gem::Net::HTTP.put]:
530
+ # Sends a PUT request with data and returns a response object.
531
+ # - {#copy}[rdoc-ref:Gem::Net::HTTP#copy]:
532
+ # Sends a COPY request and returns a response object.
533
+ # - {#delete}[rdoc-ref:Gem::Net::HTTP#delete]:
534
+ # Sends a DELETE request and returns a response object.
535
+ # - {#get}[rdoc-ref:Gem::Net::HTTP#get]:
536
+ # Sends a GET request and returns a response object.
537
+ # - {#head}[rdoc-ref:Gem::Net::HTTP#head]:
538
+ # Sends a HEAD request and returns a response object.
539
+ # - {#lock}[rdoc-ref:Gem::Net::HTTP#lock]:
540
+ # Sends a LOCK request and returns a response object.
541
+ # - {#mkcol}[rdoc-ref:Gem::Net::HTTP#mkcol]:
542
+ # Sends a MKCOL request and returns a response object.
543
+ # - {#move}[rdoc-ref:Gem::Net::HTTP#move]:
544
+ # Sends a MOVE request and returns a response object.
545
+ # - {#options}[rdoc-ref:Gem::Net::HTTP#options]:
546
+ # Sends a OPTIONS request and returns a response object.
547
+ # - {#patch}[rdoc-ref:Gem::Net::HTTP#patch]:
548
+ # Sends a PATCH request and returns a response object.
549
+ # - {#post}[rdoc-ref:Gem::Net::HTTP#post]:
550
+ # Sends a POST request and returns a response object.
551
+ # - {#propfind}[rdoc-ref:Gem::Net::HTTP#propfind]:
552
+ # Sends a PROPFIND request and returns a response object.
553
+ # - {#proppatch}[rdoc-ref:Gem::Net::HTTP#proppatch]:
554
+ # Sends a PROPPATCH request and returns a response object.
555
+ # - {#put}[rdoc-ref:Gem::Net::HTTP#put]:
556
+ # Sends a PUT request and returns a response object.
557
+ # - {#request}[rdoc-ref:Gem::Net::HTTP#request]:
558
+ # Sends a request and returns a response object.
559
+ # - {#request_get}[rdoc-ref:Gem::Net::HTTP#request_get]
560
+ # (aliased as {#get2}[rdoc-ref:Gem::Net::HTTP#get2]):
561
+ # Sends a GET request and forms a response object;
562
+ # if a block given, calls the block with the object,
563
+ # otherwise returns the object.
564
+ # - {#request_head}[rdoc-ref:Gem::Net::HTTP#request_head]
565
+ # (aliased as {#head2}[rdoc-ref:Gem::Net::HTTP#head2]):
566
+ # Sends a HEAD request and forms a response object;
567
+ # if a block given, calls the block with the object,
568
+ # otherwise returns the object.
569
+ # - {#request_post}[rdoc-ref:Gem::Net::HTTP#request_post]
570
+ # (aliased as {#post2}[rdoc-ref:Gem::Net::HTTP#post2]):
571
+ # Sends a POST request and forms a response object;
572
+ # if a block given, calls the block with the object,
573
+ # otherwise returns the object.
574
+ # - {#send_request}[rdoc-ref:Gem::Net::HTTP#send_request]:
575
+ # Sends a request and returns a response object.
576
+ # - {#trace}[rdoc-ref:Gem::Net::HTTP#trace]:
577
+ # Sends a TRACE request and returns a response object.
578
+ # - {#unlock}[rdoc-ref:Gem::Net::HTTP#unlock]:
579
+ # Sends an UNLOCK request and returns a response object.
580
+ #
581
+ # === Responses
582
+ #
583
+ # - {:close_on_empty_response}[rdoc-ref:Gem::Net::HTTP#close_on_empty_response]:
584
+ # Returns whether to close connection on empty response.
585
+ # - {:close_on_empty_response=}[rdoc-ref:Gem::Net::HTTP#close_on_empty_response=]:
586
+ # Sets whether to close connection on empty response.
587
+ # - {:ignore_eof}[rdoc-ref:Gem::Net::HTTP#ignore_eof]:
588
+ # Returns whether to ignore end-of-file when reading a response body
589
+ # with <tt>Content-Length</tt> headers.
590
+ # - {:ignore_eof=}[rdoc-ref:Gem::Net::HTTP#ignore_eof=]:
591
+ # Sets whether to ignore end-of-file when reading a response body
592
+ # with <tt>Content-Length</tt> headers.
593
+ # - {:response_body_encoding}[rdoc-ref:Gem::Net::HTTP#response_body_encoding]:
594
+ # Returns the encoding to use for the response body.
595
+ # - {#response_body_encoding=}[rdoc-ref:Gem::Net::HTTP#response_body_encoding=]:
596
+ # Sets the response body encoding.
597
+ #
598
+ # === Proxies
599
+ #
600
+ # - {:proxy_address}[rdoc-ref:Gem::Net::HTTP#proxy_address]:
601
+ # Returns the proxy address.
602
+ # - {:proxy_address=}[rdoc-ref:Gem::Net::HTTP#proxy_address=]:
603
+ # Sets the proxy address.
604
+ # - {::proxy_class?}[rdoc-ref:Gem::Net::HTTP.proxy_class?]:
605
+ # Returns whether +self+ is a proxy class.
606
+ # - {#proxy?}[rdoc-ref:Gem::Net::HTTP#proxy?]:
607
+ # Returns whether +self+ has a proxy.
608
+ # - {#proxy_address}[rdoc-ref:Gem::Net::HTTP#proxy_address]
609
+ # (aliased as {#proxyaddr}[rdoc-ref:Gem::Net::HTTP#proxyaddr]):
610
+ # Returns the proxy address.
611
+ # - {#proxy_from_env?}[rdoc-ref:Gem::Net::HTTP#proxy_from_env?]:
612
+ # Returns whether the proxy is taken from an environment variable.
613
+ # - {:proxy_from_env=}[rdoc-ref:Gem::Net::HTTP#proxy_from_env=]:
614
+ # Sets whether the proxy is to be taken from an environment variable.
615
+ # - {:proxy_pass}[rdoc-ref:Gem::Net::HTTP#proxy_pass]:
616
+ # Returns the proxy password.
617
+ # - {:proxy_pass=}[rdoc-ref:Gem::Net::HTTP#proxy_pass=]:
618
+ # Sets the proxy password.
619
+ # - {:proxy_port}[rdoc-ref:Gem::Net::HTTP#proxy_port]:
620
+ # Returns the proxy port.
621
+ # - {:proxy_port=}[rdoc-ref:Gem::Net::HTTP#proxy_port=]:
622
+ # Sets the proxy port.
623
+ # - {#proxy_user}[rdoc-ref:Gem::Net::HTTP#proxy_user]:
624
+ # Returns the proxy user name.
625
+ # - {:proxy_user=}[rdoc-ref:Gem::Net::HTTP#proxy_user=]:
626
+ # Sets the proxy user.
627
+ #
628
+ # === Security
629
+ #
630
+ # - {:ca_file}[rdoc-ref:Gem::Net::HTTP#ca_file]:
631
+ # Returns the path to a CA certification file.
632
+ # - {:ca_file=}[rdoc-ref:Gem::Net::HTTP#ca_file=]:
633
+ # Sets the path to a CA certification file.
634
+ # - {:ca_path}[rdoc-ref:Gem::Net::HTTP#ca_path]:
635
+ # Returns the path of to CA directory containing certification files.
636
+ # - {:ca_path=}[rdoc-ref:Gem::Net::HTTP#ca_path=]:
637
+ # Sets the path of to CA directory containing certification files.
638
+ # - {:cert}[rdoc-ref:Gem::Net::HTTP#cert]:
639
+ # Returns the OpenSSL::X509::Certificate object to be used for client certification.
640
+ # - {:cert=}[rdoc-ref:Gem::Net::HTTP#cert=]:
641
+ # Sets the OpenSSL::X509::Certificate object to be used for client certification.
642
+ # - {:cert_store}[rdoc-ref:Gem::Net::HTTP#cert_store]:
643
+ # Returns the X509::Store to be used for verifying peer certificate.
644
+ # - {:cert_store=}[rdoc-ref:Gem::Net::HTTP#cert_store=]:
645
+ # Sets the X509::Store to be used for verifying peer certificate.
646
+ # - {:ciphers}[rdoc-ref:Gem::Net::HTTP#ciphers]:
647
+ # Returns the available SSL ciphers.
648
+ # - {:ciphers=}[rdoc-ref:Gem::Net::HTTP#ciphers=]:
649
+ # Sets the available SSL ciphers.
650
+ # - {:extra_chain_cert}[rdoc-ref:Gem::Net::HTTP#extra_chain_cert]:
651
+ # Returns the extra X509 certificates to be added to the certificate chain.
652
+ # - {:extra_chain_cert=}[rdoc-ref:Gem::Net::HTTP#extra_chain_cert=]:
653
+ # Sets the extra X509 certificates to be added to the certificate chain.
654
+ # - {:key}[rdoc-ref:Gem::Net::HTTP#key]:
655
+ # Returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
656
+ # - {:key=}[rdoc-ref:Gem::Net::HTTP#key=]:
657
+ # Sets the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
658
+ # - {:max_version}[rdoc-ref:Gem::Net::HTTP#max_version]:
659
+ # Returns the maximum SSL version.
660
+ # - {:max_version=}[rdoc-ref:Gem::Net::HTTP#max_version=]:
661
+ # Sets the maximum SSL version.
662
+ # - {:min_version}[rdoc-ref:Gem::Net::HTTP#min_version]:
663
+ # Returns the minimum SSL version.
664
+ # - {:min_version=}[rdoc-ref:Gem::Net::HTTP#min_version=]:
665
+ # Sets the minimum SSL version.
666
+ # - {#peer_cert}[rdoc-ref:Gem::Net::HTTP#peer_cert]:
667
+ # Returns the X509 certificate chain for the session's socket peer.
668
+ # - {:ssl_version}[rdoc-ref:Gem::Net::HTTP#ssl_version]:
669
+ # Returns the SSL version.
670
+ # - {:ssl_version=}[rdoc-ref:Gem::Net::HTTP#ssl_version=]:
671
+ # Sets the SSL version.
672
+ # - {#use_ssl=}[rdoc-ref:Gem::Net::HTTP#use_ssl=]:
673
+ # Sets whether a new session is to use Transport Layer Security.
674
+ # - {#use_ssl?}[rdoc-ref:Gem::Net::HTTP#use_ssl?]:
675
+ # Returns whether +self+ uses SSL.
676
+ # - {:verify_callback}[rdoc-ref:Gem::Net::HTTP#verify_callback]:
677
+ # Returns the callback for the server certification verification.
678
+ # - {:verify_callback=}[rdoc-ref:Gem::Net::HTTP#verify_callback=]:
679
+ # Sets the callback for the server certification verification.
680
+ # - {:verify_depth}[rdoc-ref:Gem::Net::HTTP#verify_depth]:
681
+ # Returns the maximum depth for the certificate chain verification.
682
+ # - {:verify_depth=}[rdoc-ref:Gem::Net::HTTP#verify_depth=]:
683
+ # Sets the maximum depth for the certificate chain verification.
684
+ # - {:verify_hostname}[rdoc-ref:Gem::Net::HTTP#verify_hostname]:
685
+ # Returns the flags for server the certification verification at the beginning of the SSL/TLS session.
686
+ # - {:verify_hostname=}[rdoc-ref:Gem::Net::HTTP#verify_hostname=]:
687
+ # Sets he flags for server the certification verification at the beginning of the SSL/TLS session.
688
+ # - {:verify_mode}[rdoc-ref:Gem::Net::HTTP#verify_mode]:
689
+ # Returns the flags for server the certification verification at the beginning of the SSL/TLS session.
690
+ # - {:verify_mode=}[rdoc-ref:Gem::Net::HTTP#verify_mode=]:
691
+ # Sets the flags for server the certification verification at the beginning of the SSL/TLS session.
692
+ #
693
+ # === Addresses and Ports
694
+ #
695
+ # - {:address}[rdoc-ref:Gem::Net::HTTP#address]:
696
+ # Returns the string host name or host IP.
697
+ # - {::default_port}[rdoc-ref:Gem::Net::HTTP.default_port]:
698
+ # Returns integer 80, the default port to use for HTTP requests.
699
+ # - {::http_default_port}[rdoc-ref:Gem::Net::HTTP.http_default_port]:
700
+ # Returns integer 80, the default port to use for HTTP requests.
701
+ # - {::https_default_port}[rdoc-ref:Gem::Net::HTTP.https_default_port]:
702
+ # Returns integer 443, the default port to use for HTTPS requests.
703
+ # - {#ipaddr}[rdoc-ref:Gem::Net::HTTP#ipaddr]:
704
+ # Returns the IP address for the connection.
705
+ # - {#ipaddr=}[rdoc-ref:Gem::Net::HTTP#ipaddr=]:
706
+ # Sets the IP address for the connection.
707
+ # - {:local_host}[rdoc-ref:Gem::Net::HTTP#local_host]:
708
+ # Returns the string local host used to establish the connection.
709
+ # - {:local_host=}[rdoc-ref:Gem::Net::HTTP#local_host=]:
710
+ # Sets the string local host used to establish the connection.
711
+ # - {:local_port}[rdoc-ref:Gem::Net::HTTP#local_port]:
712
+ # Returns the integer local port used to establish the connection.
713
+ # - {:local_port=}[rdoc-ref:Gem::Net::HTTP#local_port=]:
714
+ # Sets the integer local port used to establish the connection.
715
+ # - {:port}[rdoc-ref:Gem::Net::HTTP#port]:
716
+ # Returns the integer port number.
717
+ #
718
+ # === \HTTP Version
719
+ #
720
+ # - {::version_1_2?}[rdoc-ref:Gem::Net::HTTP.version_1_2?]
721
+ # (aliased as {::is_version_1_2?}[rdoc-ref:Gem::Net::HTTP.is_version_1_2?]
722
+ # and {::version_1_2}[rdoc-ref:Gem::Net::HTTP.version_1_2]):
723
+ # Returns true; retained for compatibility.
724
+ #
725
+ # === Debugging
726
+ #
727
+ # - {#set_debug_output}[rdoc-ref:Gem::Net::HTTP#set_debug_output]:
728
+ # Sets the output stream for debugging.
729
+ #
730
+ class HTTP < Protocol
731
+
732
+ # :stopdoc:
733
+ VERSION = "0.6.0"
734
+ HTTPVersion = '1.1'
735
+ begin
736
+ require 'zlib'
737
+ HAVE_ZLIB=true
738
+ rescue LoadError
739
+ HAVE_ZLIB=false
740
+ end
741
+ # :startdoc:
742
+
743
+ # Returns +true+; retained for compatibility.
744
+ def HTTP.version_1_2
745
+ true
746
+ end
747
+
748
+ # Returns +true+; retained for compatibility.
749
+ def HTTP.version_1_2?
750
+ true
751
+ end
752
+
753
+ # Returns +false+; retained for compatibility.
754
+ def HTTP.version_1_1? #:nodoc:
755
+ false
756
+ end
757
+
758
+ class << HTTP
759
+ alias is_version_1_1? version_1_1? #:nodoc:
760
+ alias is_version_1_2? version_1_2? #:nodoc:
761
+ end
762
+
763
+ # :call-seq:
764
+ # Gem::Net::HTTP.get_print(hostname, path, port = 80) -> nil
765
+ # Gem::Net::HTTP:get_print(uri, headers = {}, port = uri.port) -> nil
766
+ #
767
+ # Like Gem::Net::HTTP.get, but writes the returned body to $stdout;
768
+ # returns +nil+.
769
+ def HTTP.get_print(uri_or_host, path_or_headers = nil, port = nil)
770
+ get_response(uri_or_host, path_or_headers, port) {|res|
771
+ res.read_body do |chunk|
772
+ $stdout.print chunk
773
+ end
774
+ }
775
+ nil
776
+ end
777
+
778
+ # :call-seq:
779
+ # Gem::Net::HTTP.get(hostname, path, port = 80) -> body
780
+ # Gem::Net::HTTP:get(uri, headers = {}, port = uri.port) -> body
781
+ #
782
+ # Sends a GET request and returns the \HTTP response body as a string.
783
+ #
784
+ # With string arguments +hostname+ and +path+:
785
+ #
786
+ # hostname = 'jsonplaceholder.typicode.com'
787
+ # path = '/todos/1'
788
+ # puts Gem::Net::HTTP.get(hostname, path)
789
+ #
790
+ # Output:
791
+ #
792
+ # {
793
+ # "userId": 1,
794
+ # "id": 1,
795
+ # "title": "delectus aut autem",
796
+ # "completed": false
797
+ # }
798
+ #
799
+ # With URI object +uri+ and optional hash argument +headers+:
800
+ #
801
+ # uri = Gem::URI('https://jsonplaceholder.typicode.com/todos/1')
802
+ # headers = {'Content-type' => 'application/json; charset=UTF-8'}
803
+ # Gem::Net::HTTP.get(uri, headers)
804
+ #
805
+ # Related:
806
+ #
807
+ # - Gem::Net::HTTP::Get: request class for \HTTP method +GET+.
808
+ # - Gem::Net::HTTP#get: convenience method for \HTTP method +GET+.
809
+ #
810
+ def HTTP.get(uri_or_host, path_or_headers = nil, port = nil)
811
+ get_response(uri_or_host, path_or_headers, port).body
812
+ end
813
+
814
+ # :call-seq:
815
+ # Gem::Net::HTTP.get_response(hostname, path, port = 80) -> http_response
816
+ # Gem::Net::HTTP:get_response(uri, headers = {}, port = uri.port) -> http_response
817
+ #
818
+ # Like Gem::Net::HTTP.get, but returns a Gem::Net::HTTPResponse object
819
+ # instead of the body string.
820
+ def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
821
+ if path_or_headers && !path_or_headers.is_a?(Hash)
822
+ host = uri_or_host
823
+ path = path_or_headers
824
+ new(host, port || HTTP.default_port).start {|http|
825
+ return http.request_get(path, &block)
826
+ }
827
+ else
828
+ uri = uri_or_host
829
+ headers = path_or_headers
830
+ start(uri.hostname, uri.port,
831
+ :use_ssl => uri.scheme == 'https') {|http|
832
+ return http.request_get(uri, headers, &block)
833
+ }
834
+ end
835
+ end
836
+
837
+ # Posts data to a host; returns a Gem::Net::HTTPResponse object.
838
+ #
839
+ # Argument +url+ must be a URL;
840
+ # argument +data+ must be a string:
841
+ #
842
+ # _uri = uri.dup
843
+ # _uri.path = '/posts'
844
+ # data = '{"title": "foo", "body": "bar", "userId": 1}'
845
+ # headers = {'content-type': 'application/json'}
846
+ # res = Gem::Net::HTTP.post(_uri, data, headers) # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
847
+ # puts res.body
848
+ #
849
+ # Output:
850
+ #
851
+ # {
852
+ # "title": "foo",
853
+ # "body": "bar",
854
+ # "userId": 1,
855
+ # "id": 101
856
+ # }
857
+ #
858
+ # Related:
859
+ #
860
+ # - Gem::Net::HTTP::Post: request class for \HTTP method +POST+.
861
+ # - Gem::Net::HTTP#post: convenience method for \HTTP method +POST+.
862
+ #
863
+ def HTTP.post(url, data, header = nil)
864
+ start(url.hostname, url.port,
865
+ :use_ssl => url.scheme == 'https' ) {|http|
866
+ http.post(url, data, header)
867
+ }
868
+ end
869
+
870
+ # Posts data to a host; returns a Gem::Net::HTTPResponse object.
871
+ #
872
+ # Argument +url+ must be a URI;
873
+ # argument +data+ must be a hash:
874
+ #
875
+ # _uri = uri.dup
876
+ # _uri.path = '/posts'
877
+ # data = {title: 'foo', body: 'bar', userId: 1}
878
+ # res = Gem::Net::HTTP.post_form(_uri, data) # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
879
+ # puts res.body
880
+ #
881
+ # Output:
882
+ #
883
+ # {
884
+ # "title": "foo",
885
+ # "body": "bar",
886
+ # "userId": "1",
887
+ # "id": 101
888
+ # }
889
+ #
890
+ def HTTP.post_form(url, params)
891
+ req = Post.new(url)
892
+ req.form_data = params
893
+ req.basic_auth url.user, url.password if url.user
894
+ start(url.hostname, url.port,
895
+ :use_ssl => url.scheme == 'https' ) {|http|
896
+ http.request(req)
897
+ }
898
+ end
899
+
900
+ # Sends a PUT request to the server; returns a Gem::Net::HTTPResponse object.
901
+ #
902
+ # Argument +url+ must be a URL;
903
+ # argument +data+ must be a string:
904
+ #
905
+ # _uri = uri.dup
906
+ # _uri.path = '/posts'
907
+ # data = '{"title": "foo", "body": "bar", "userId": 1}'
908
+ # headers = {'content-type': 'application/json'}
909
+ # res = Gem::Net::HTTP.put(_uri, data, headers) # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
910
+ # puts res.body
911
+ #
912
+ # Output:
913
+ #
914
+ # {
915
+ # "title": "foo",
916
+ # "body": "bar",
917
+ # "userId": 1,
918
+ # "id": 101
919
+ # }
920
+ #
921
+ # Related:
922
+ #
923
+ # - Gem::Net::HTTP::Put: request class for \HTTP method +PUT+.
924
+ # - Gem::Net::HTTP#put: convenience method for \HTTP method +PUT+.
925
+ #
926
+ def HTTP.put(url, data, header = nil)
927
+ start(url.hostname, url.port,
928
+ :use_ssl => url.scheme == 'https' ) {|http|
929
+ http.put(url, data, header)
930
+ }
931
+ end
932
+
933
+ #
934
+ # \HTTP session management
935
+ #
936
+
937
+ # Returns integer +80+, the default port to use for \HTTP requests:
938
+ #
939
+ # Gem::Net::HTTP.default_port # => 80
940
+ #
941
+ def HTTP.default_port
942
+ http_default_port()
943
+ end
944
+
945
+ # Returns integer +80+, the default port to use for \HTTP requests:
946
+ #
947
+ # Gem::Net::HTTP.http_default_port # => 80
948
+ #
949
+ def HTTP.http_default_port
950
+ 80
951
+ end
952
+
953
+ # Returns integer +443+, the default port to use for HTTPS requests:
954
+ #
955
+ # Gem::Net::HTTP.https_default_port # => 443
956
+ #
957
+ def HTTP.https_default_port
958
+ 443
959
+ end
960
+
961
+ def HTTP.socket_type #:nodoc: obsolete
962
+ BufferedIO
963
+ end
964
+
965
+ # :call-seq:
966
+ # HTTP.start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) -> http
967
+ # HTTP.start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) {|http| ... } -> object
968
+ #
969
+ # Creates a new \Gem::Net::HTTP object, +http+, via \Gem::Net::HTTP.new:
970
+ #
971
+ # - For arguments +address+ and +port+, see Gem::Net::HTTP.new.
972
+ # - For proxy-defining arguments +p_addr+ through +p_pass+,
973
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
974
+ # - For argument +opts+, see below.
975
+ #
976
+ # With no block given:
977
+ #
978
+ # - Calls <tt>http.start</tt> with no block (see #start),
979
+ # which opens a TCP connection and \HTTP session.
980
+ # - Returns +http+.
981
+ # - The caller should call #finish to close the session:
982
+ #
983
+ # http = Gem::Net::HTTP.start(hostname)
984
+ # http.started? # => true
985
+ # http.finish
986
+ # http.started? # => false
987
+ #
988
+ # With a block given:
989
+ #
990
+ # - Calls <tt>http.start</tt> with the block (see #start), which:
991
+ #
992
+ # - Opens a TCP connection and \HTTP session.
993
+ # - Calls the block,
994
+ # which may make any number of requests to the host.
995
+ # - Closes the \HTTP session and TCP connection on block exit.
996
+ # - Returns the block's value +object+.
997
+ #
998
+ # - Returns +object+.
999
+ #
1000
+ # Example:
1001
+ #
1002
+ # hostname = 'jsonplaceholder.typicode.com'
1003
+ # Gem::Net::HTTP.start(hostname) do |http|
1004
+ # puts http.get('/todos/1').body
1005
+ # puts http.get('/todos/2').body
1006
+ # end
1007
+ #
1008
+ # Output:
1009
+ #
1010
+ # {
1011
+ # "userId": 1,
1012
+ # "id": 1,
1013
+ # "title": "delectus aut autem",
1014
+ # "completed": false
1015
+ # }
1016
+ # {
1017
+ # "userId": 1,
1018
+ # "id": 2,
1019
+ # "title": "quis ut nam facilis et officia qui",
1020
+ # "completed": false
1021
+ # }
1022
+ #
1023
+ # If the last argument given is a hash, it is the +opts+ hash,
1024
+ # where each key is a method or accessor to be called,
1025
+ # and its value is the value to be set.
1026
+ #
1027
+ # The keys may include:
1028
+ #
1029
+ # - #ca_file
1030
+ # - #ca_path
1031
+ # - #cert
1032
+ # - #cert_store
1033
+ # - #ciphers
1034
+ # - #close_on_empty_response
1035
+ # - +ipaddr+ (calls #ipaddr=)
1036
+ # - #keep_alive_timeout
1037
+ # - #key
1038
+ # - #open_timeout
1039
+ # - #read_timeout
1040
+ # - #ssl_timeout
1041
+ # - #ssl_version
1042
+ # - +use_ssl+ (calls #use_ssl=)
1043
+ # - #verify_callback
1044
+ # - #verify_depth
1045
+ # - #verify_mode
1046
+ # - #write_timeout
1047
+ #
1048
+ # Note: If +port+ is +nil+ and <tt>opts[:use_ssl]</tt> is a truthy value,
1049
+ # the value passed to +new+ is Gem::Net::HTTP.https_default_port, not +port+.
1050
+ #
1051
+ def HTTP.start(address, *arg, &block) # :yield: +http+
1052
+ arg.pop if opt = Hash.try_convert(arg[-1])
1053
+ port, p_addr, p_port, p_user, p_pass = *arg
1054
+ p_addr = :ENV if arg.size < 2
1055
+ port = https_default_port if !port && opt && opt[:use_ssl]
1056
+ http = new(address, port, p_addr, p_port, p_user, p_pass)
1057
+ http.ipaddr = opt[:ipaddr] if opt && opt[:ipaddr]
1058
+
1059
+ if opt
1060
+ if opt[:use_ssl]
1061
+ opt = {verify_mode: OpenSSL::SSL::VERIFY_PEER}.update(opt)
1062
+ end
1063
+ http.methods.grep(/\A(\w+)=\z/) do |meth|
1064
+ key = $1.to_sym
1065
+ opt.key?(key) or next
1066
+ http.__send__(meth, opt[key])
1067
+ end
1068
+ end
1069
+
1070
+ http.start(&block)
1071
+ end
1072
+
1073
+ class << HTTP
1074
+ alias newobj new # :nodoc:
1075
+ end
1076
+
1077
+ # Returns a new \Gem::Net::HTTP object +http+
1078
+ # (but does not open a TCP connection or \HTTP session).
1079
+ #
1080
+ # With only string argument +address+ given
1081
+ # (and <tt>ENV['http_proxy']</tt> undefined or +nil+),
1082
+ # the returned +http+:
1083
+ #
1084
+ # - Has the given address.
1085
+ # - Has the default port number, Gem::Net::HTTP.default_port (80).
1086
+ # - Has no proxy.
1087
+ #
1088
+ # Example:
1089
+ #
1090
+ # http = Gem::Net::HTTP.new(hostname)
1091
+ # # => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>
1092
+ # http.address # => "jsonplaceholder.typicode.com"
1093
+ # http.port # => 80
1094
+ # http.proxy? # => false
1095
+ #
1096
+ # With integer argument +port+ also given,
1097
+ # the returned +http+ has the given port:
1098
+ #
1099
+ # http = Gem::Net::HTTP.new(hostname, 8000)
1100
+ # # => #<Gem::Net::HTTP jsonplaceholder.typicode.com:8000 open=false>
1101
+ # http.port # => 8000
1102
+ #
1103
+ # For proxy-defining arguments +p_addr+ through +p_no_proxy+,
1104
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1105
+ #
1106
+ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_no_proxy = nil, p_use_ssl = nil)
1107
+ http = super address, port
1108
+
1109
+ if proxy_class? then # from Gem::Net::HTTP::Proxy()
1110
+ http.proxy_from_env = @proxy_from_env
1111
+ http.proxy_address = @proxy_address
1112
+ http.proxy_port = @proxy_port
1113
+ http.proxy_user = @proxy_user
1114
+ http.proxy_pass = @proxy_pass
1115
+ http.proxy_use_ssl = @proxy_use_ssl
1116
+ elsif p_addr == :ENV then
1117
+ http.proxy_from_env = true
1118
+ else
1119
+ if p_addr && p_no_proxy && !Gem::URI::Generic.use_proxy?(address, address, port, p_no_proxy)
1120
+ p_addr = nil
1121
+ p_port = nil
1122
+ end
1123
+ http.proxy_address = p_addr
1124
+ http.proxy_port = p_port || default_port
1125
+ http.proxy_user = p_user
1126
+ http.proxy_pass = p_pass
1127
+ http.proxy_use_ssl = p_use_ssl
1128
+ end
1129
+
1130
+ http
1131
+ end
1132
+
1133
+ class << HTTP
1134
+ # Allows to set the default configuration that will be used
1135
+ # when creating a new connection.
1136
+ #
1137
+ # Example:
1138
+ #
1139
+ # Gem::Net::HTTP.default_configuration = {
1140
+ # read_timeout: 1,
1141
+ # write_timeout: 1
1142
+ # }
1143
+ # http = Gem::Net::HTTP.new(hostname)
1144
+ # http.open_timeout # => 60
1145
+ # http.read_timeout # => 1
1146
+ # http.write_timeout # => 1
1147
+ #
1148
+ attr_accessor :default_configuration
1149
+ end
1150
+
1151
+ # Creates a new \Gem::Net::HTTP object for the specified server address,
1152
+ # without opening the TCP connection or initializing the \HTTP session.
1153
+ # The +address+ should be a DNS hostname or IP address.
1154
+ def initialize(address, port = nil) # :nodoc:
1155
+ defaults = {
1156
+ keep_alive_timeout: 2,
1157
+ close_on_empty_response: false,
1158
+ open_timeout: 60,
1159
+ read_timeout: 60,
1160
+ write_timeout: 60,
1161
+ continue_timeout: nil,
1162
+ max_retries: 1,
1163
+ debug_output: nil,
1164
+ response_body_encoding: false,
1165
+ ignore_eof: true
1166
+ }
1167
+ options = defaults.merge(self.class.default_configuration || {})
1168
+
1169
+ @address = address
1170
+ @port = (port || HTTP.default_port)
1171
+ @ipaddr = nil
1172
+ @local_host = nil
1173
+ @local_port = nil
1174
+ @curr_http_version = HTTPVersion
1175
+ @keep_alive_timeout = options[:keep_alive_timeout]
1176
+ @last_communicated = nil
1177
+ @close_on_empty_response = options[:close_on_empty_response]
1178
+ @socket = nil
1179
+ @started = false
1180
+ @open_timeout = options[:open_timeout]
1181
+ @read_timeout = options[:read_timeout]
1182
+ @write_timeout = options[:write_timeout]
1183
+ @continue_timeout = options[:continue_timeout]
1184
+ @max_retries = options[:max_retries]
1185
+ @debug_output = options[:debug_output]
1186
+ @response_body_encoding = options[:response_body_encoding]
1187
+ @ignore_eof = options[:ignore_eof]
1188
+
1189
+ @proxy_from_env = false
1190
+ @proxy_uri = nil
1191
+ @proxy_address = nil
1192
+ @proxy_port = nil
1193
+ @proxy_user = nil
1194
+ @proxy_pass = nil
1195
+ @proxy_use_ssl = nil
1196
+
1197
+ @use_ssl = false
1198
+ @ssl_context = nil
1199
+ @ssl_session = nil
1200
+ @sspi_enabled = false
1201
+ SSL_IVNAMES.each do |ivname|
1202
+ instance_variable_set ivname, nil
1203
+ end
1204
+ end
1205
+
1206
+ # Returns a string representation of +self+:
1207
+ #
1208
+ # Gem::Net::HTTP.new(hostname).inspect
1209
+ # # => "#<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>"
1210
+ #
1211
+ def inspect
1212
+ "#<#{self.class} #{@address}:#{@port} open=#{started?}>"
1213
+ end
1214
+
1215
+ # *WARNING* This method opens a serious security hole.
1216
+ # Never use this method in production code.
1217
+ #
1218
+ # Sets the output stream for debugging:
1219
+ #
1220
+ # http = Gem::Net::HTTP.new(hostname)
1221
+ # File.open('t.tmp', 'w') do |file|
1222
+ # http.set_debug_output(file)
1223
+ # http.start
1224
+ # http.get('/nosuch/1')
1225
+ # http.finish
1226
+ # end
1227
+ # puts File.read('t.tmp')
1228
+ #
1229
+ # Output:
1230
+ #
1231
+ # opening connection to jsonplaceholder.typicode.com:80...
1232
+ # opened
1233
+ # <- "GET /nosuch/1 HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nHost: jsonplaceholder.typicode.com\r\n\r\n"
1234
+ # -> "HTTP/1.1 404 Not Found\r\n"
1235
+ # -> "Date: Mon, 12 Dec 2022 21:14:11 GMT\r\n"
1236
+ # -> "Content-Type: application/json; charset=utf-8\r\n"
1237
+ # -> "Content-Length: 2\r\n"
1238
+ # -> "Connection: keep-alive\r\n"
1239
+ # -> "X-Powered-By: Express\r\n"
1240
+ # -> "X-Ratelimit-Limit: 1000\r\n"
1241
+ # -> "X-Ratelimit-Remaining: 999\r\n"
1242
+ # -> "X-Ratelimit-Reset: 1670879660\r\n"
1243
+ # -> "Vary: Origin, Accept-Encoding\r\n"
1244
+ # -> "Access-Control-Allow-Credentials: true\r\n"
1245
+ # -> "Cache-Control: max-age=43200\r\n"
1246
+ # -> "Pragma: no-cache\r\n"
1247
+ # -> "Expires: -1\r\n"
1248
+ # -> "X-Content-Type-Options: nosniff\r\n"
1249
+ # -> "Etag: W/\"2-vyGp6PvFo4RvsFtPoIWeCReyIC8\"\r\n"
1250
+ # -> "Via: 1.1 vegur\r\n"
1251
+ # -> "CF-Cache-Status: MISS\r\n"
1252
+ # -> "Server-Timing: cf-q-config;dur=1.3000000762986e-05\r\n"
1253
+ # -> "Report-To: {\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=yOr40jo%2BwS1KHzhTlVpl54beJ5Wx2FcG4gGV0XVrh3X9OlR5q4drUn2dkt5DGO4GDcE%2BVXT7CNgJvGs%2BZleIyMu8CLieFiDIvOviOY3EhHg94m0ZNZgrEdpKD0S85S507l1vsEwEHkoTm%2Ff19SiO\"}],\"group\":\"cf-nel\",\"max_age\":604800}\r\n"
1254
+ # -> "NEL: {\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}\r\n"
1255
+ # -> "Server: cloudflare\r\n"
1256
+ # -> "CF-RAY: 778977dc484ce591-DFW\r\n"
1257
+ # -> "alt-svc: h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400\r\n"
1258
+ # -> "\r\n"
1259
+ # reading 2 bytes...
1260
+ # -> "{}"
1261
+ # read 2 bytes
1262
+ # Conn keep-alive
1263
+ #
1264
+ def set_debug_output(output)
1265
+ warn 'Gem::Net::HTTP#set_debug_output called after HTTP started', uplevel: 1 if started?
1266
+ @debug_output = output
1267
+ end
1268
+
1269
+ # Returns the string host name or host IP given as argument +address+ in ::new.
1270
+ attr_reader :address
1271
+
1272
+ # Returns the integer port number given as argument +port+ in ::new.
1273
+ attr_reader :port
1274
+
1275
+ # Sets or returns the string local host used to establish the connection;
1276
+ # initially +nil+.
1277
+ attr_accessor :local_host
1278
+
1279
+ # Sets or returns the integer local port used to establish the connection;
1280
+ # initially +nil+.
1281
+ attr_accessor :local_port
1282
+
1283
+ # Returns the encoding to use for the response body;
1284
+ # see #response_body_encoding=.
1285
+ attr_reader :response_body_encoding
1286
+
1287
+ # Sets the encoding to be used for the response body;
1288
+ # returns the encoding.
1289
+ #
1290
+ # The given +value+ may be:
1291
+ #
1292
+ # - An Encoding object.
1293
+ # - The name of an encoding.
1294
+ # - An alias for an encoding name.
1295
+ #
1296
+ # See {Encoding}[https://docs.ruby-lang.org/en/master/Encoding.html].
1297
+ #
1298
+ # Examples:
1299
+ #
1300
+ # http = Gem::Net::HTTP.new(hostname)
1301
+ # http.response_body_encoding = Encoding::US_ASCII # => #<Encoding:US-ASCII>
1302
+ # http.response_body_encoding = 'US-ASCII' # => "US-ASCII"
1303
+ # http.response_body_encoding = 'ASCII' # => "ASCII"
1304
+ #
1305
+ def response_body_encoding=(value)
1306
+ value = Encoding.find(value) if value.is_a?(String)
1307
+ @response_body_encoding = value
1308
+ end
1309
+
1310
+ # Sets whether to determine the proxy from environment variable
1311
+ # '<tt>ENV['http_proxy']</tt>';
1312
+ # see {Proxy Using ENV['http_proxy']}[rdoc-ref:Gem::Net::HTTP@Proxy+Using+-27ENV-5B-27http_proxy-27-5D-27].
1313
+ attr_writer :proxy_from_env
1314
+
1315
+ # Sets the proxy address;
1316
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1317
+ attr_writer :proxy_address
1318
+
1319
+ # Sets the proxy port;
1320
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1321
+ attr_writer :proxy_port
1322
+
1323
+ # Sets the proxy user;
1324
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1325
+ attr_writer :proxy_user
1326
+
1327
+ # Sets the proxy password;
1328
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1329
+ attr_writer :proxy_pass
1330
+ attr_writer :proxy_use_ssl
1331
+
1332
+ # Returns the IP address for the connection.
1333
+ #
1334
+ # If the session has not been started,
1335
+ # returns the value set by #ipaddr=,
1336
+ # or +nil+ if it has not been set:
1337
+ #
1338
+ # http = Gem::Net::HTTP.new(hostname)
1339
+ # http.ipaddr # => nil
1340
+ # http.ipaddr = '172.67.155.76'
1341
+ # http.ipaddr # => "172.67.155.76"
1342
+ #
1343
+ # If the session has been started,
1344
+ # returns the IP address from the socket:
1345
+ #
1346
+ # http = Gem::Net::HTTP.new(hostname)
1347
+ # http.start
1348
+ # http.ipaddr # => "172.67.155.76"
1349
+ # http.finish
1350
+ #
1351
+ def ipaddr
1352
+ started? ? @socket.io.peeraddr[3] : @ipaddr
1353
+ end
1354
+
1355
+ # Sets the IP address for the connection:
1356
+ #
1357
+ # http = Gem::Net::HTTP.new(hostname)
1358
+ # http.ipaddr # => nil
1359
+ # http.ipaddr = '172.67.155.76'
1360
+ # http.ipaddr # => "172.67.155.76"
1361
+ #
1362
+ # The IP address may not be set if the session has been started.
1363
+ def ipaddr=(addr)
1364
+ raise IOError, "ipaddr value changed, but session already started" if started?
1365
+ @ipaddr = addr
1366
+ end
1367
+
1368
+ # Sets or returns the numeric (\Integer or \Float) number of seconds
1369
+ # to wait for a connection to open;
1370
+ # initially 60.
1371
+ # If the connection is not made in the given interval,
1372
+ # an exception is raised.
1373
+ attr_accessor :open_timeout
1374
+
1375
+ # Returns the numeric (\Integer or \Float) number of seconds
1376
+ # to wait for one block to be read (via one read(2) call);
1377
+ # see #read_timeout=.
1378
+ attr_reader :read_timeout
1379
+
1380
+ # Returns the numeric (\Integer or \Float) number of seconds
1381
+ # to wait for one block to be written (via one write(2) call);
1382
+ # see #write_timeout=.
1383
+ attr_reader :write_timeout
1384
+
1385
+ # Sets the maximum number of times to retry an idempotent request in case of
1386
+ # \Gem::Net::ReadTimeout, IOError, EOFError, Errno::ECONNRESET,
1387
+ # Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError,
1388
+ # Gem::Timeout::Error.
1389
+ # The initial value is 1.
1390
+ #
1391
+ # Argument +retries+ must be a non-negative numeric value:
1392
+ #
1393
+ # http = Gem::Net::HTTP.new(hostname)
1394
+ # http.max_retries = 2 # => 2
1395
+ # http.max_retries # => 2
1396
+ #
1397
+ def max_retries=(retries)
1398
+ retries = retries.to_int
1399
+ if retries < 0
1400
+ raise ArgumentError, 'max_retries should be non-negative integer number'
1401
+ end
1402
+ @max_retries = retries
1403
+ end
1404
+
1405
+ # Returns the maximum number of times to retry an idempotent request;
1406
+ # see #max_retries=.
1407
+ attr_reader :max_retries
1408
+
1409
+ # Sets the read timeout, in seconds, for +self+ to integer +sec+;
1410
+ # the initial value is 60.
1411
+ #
1412
+ # Argument +sec+ must be a non-negative numeric value:
1413
+ #
1414
+ # http = Gem::Net::HTTP.new(hostname)
1415
+ # http.read_timeout # => 60
1416
+ # http.get('/todos/1') # => #<Gem::Net::HTTPOK 200 OK readbody=true>
1417
+ # http.read_timeout = 0
1418
+ # http.get('/todos/1') # Raises Gem::Net::ReadTimeout.
1419
+ #
1420
+ def read_timeout=(sec)
1421
+ @socket.read_timeout = sec if @socket
1422
+ @read_timeout = sec
1423
+ end
1424
+
1425
+ # Sets the write timeout, in seconds, for +self+ to integer +sec+;
1426
+ # the initial value is 60.
1427
+ #
1428
+ # Argument +sec+ must be a non-negative numeric value:
1429
+ #
1430
+ # _uri = uri.dup
1431
+ # _uri.path = '/posts'
1432
+ # body = 'bar' * 200000
1433
+ # data = <<EOF
1434
+ # {"title": "foo", "body": "#{body}", "userId": "1"}
1435
+ # EOF
1436
+ # headers = {'content-type': 'application/json'}
1437
+ # http = Gem::Net::HTTP.new(hostname)
1438
+ # http.write_timeout # => 60
1439
+ # http.post(_uri.path, data, headers)
1440
+ # # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
1441
+ # http.write_timeout = 0
1442
+ # http.post(_uri.path, data, headers) # Raises Gem::Net::WriteTimeout.
1443
+ #
1444
+ def write_timeout=(sec)
1445
+ @socket.write_timeout = sec if @socket
1446
+ @write_timeout = sec
1447
+ end
1448
+
1449
+ # Returns the continue timeout value;
1450
+ # see continue_timeout=.
1451
+ attr_reader :continue_timeout
1452
+
1453
+ # Sets the continue timeout value,
1454
+ # which is the number of seconds to wait for an expected 100 Continue response.
1455
+ # If the \HTTP object does not receive a response in this many seconds
1456
+ # it sends the request body.
1457
+ def continue_timeout=(sec)
1458
+ @socket.continue_timeout = sec if @socket
1459
+ @continue_timeout = sec
1460
+ end
1461
+
1462
+ # Sets or returns the numeric (\Integer or \Float) number of seconds
1463
+ # to keep the connection open after a request is sent;
1464
+ # initially 2.
1465
+ # If a new request is made during the given interval,
1466
+ # the still-open connection is used;
1467
+ # otherwise the connection will have been closed
1468
+ # and a new connection is opened.
1469
+ attr_accessor :keep_alive_timeout
1470
+
1471
+ # Sets or returns whether to ignore end-of-file when reading a response body
1472
+ # with <tt>Content-Length</tt> headers;
1473
+ # initially +true+.
1474
+ attr_accessor :ignore_eof
1475
+
1476
+ # Returns +true+ if the \HTTP session has been started:
1477
+ #
1478
+ # http = Gem::Net::HTTP.new(hostname)
1479
+ # http.started? # => false
1480
+ # http.start
1481
+ # http.started? # => true
1482
+ # http.finish # => nil
1483
+ # http.started? # => false
1484
+ #
1485
+ # Gem::Net::HTTP.start(hostname) do |http|
1486
+ # http.started?
1487
+ # end # => true
1488
+ # http.started? # => false
1489
+ #
1490
+ def started?
1491
+ @started
1492
+ end
1493
+
1494
+ alias active? started? #:nodoc: obsolete
1495
+
1496
+ # Sets or returns whether to close the connection when the response is empty;
1497
+ # initially +false+.
1498
+ attr_accessor :close_on_empty_response
1499
+
1500
+ # Returns +true+ if +self+ uses SSL, +false+ otherwise.
1501
+ # See Gem::Net::HTTP#use_ssl=.
1502
+ def use_ssl?
1503
+ @use_ssl
1504
+ end
1505
+
1506
+ # Sets whether a new session is to use
1507
+ # {Transport Layer Security}[https://en.wikipedia.org/wiki/Transport_Layer_Security]:
1508
+ #
1509
+ # Raises IOError if attempting to change during a session.
1510
+ #
1511
+ # Raises OpenSSL::SSL::SSLError if the port is not an HTTPS port.
1512
+ def use_ssl=(flag)
1513
+ flag = flag ? true : false
1514
+ if started? and @use_ssl != flag
1515
+ raise IOError, "use_ssl value changed, but session already started"
1516
+ end
1517
+ @use_ssl = flag
1518
+ end
1519
+
1520
+ SSL_ATTRIBUTES = [
1521
+ :ca_file,
1522
+ :ca_path,
1523
+ :cert,
1524
+ :cert_store,
1525
+ :ciphers,
1526
+ :extra_chain_cert,
1527
+ :key,
1528
+ :ssl_timeout,
1529
+ :ssl_version,
1530
+ :min_version,
1531
+ :max_version,
1532
+ :verify_callback,
1533
+ :verify_depth,
1534
+ :verify_mode,
1535
+ :verify_hostname,
1536
+ ] # :nodoc:
1537
+
1538
+ SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym } # :nodoc:
1539
+
1540
+ # Sets or returns the path to a CA certification file in PEM format.
1541
+ attr_accessor :ca_file
1542
+
1543
+ # Sets or returns the path of to CA directory
1544
+ # containing certification files in PEM format.
1545
+ attr_accessor :ca_path
1546
+
1547
+ # Sets or returns the OpenSSL::X509::Certificate object
1548
+ # to be used for client certification.
1549
+ attr_accessor :cert
1550
+
1551
+ # Sets or returns the X509::Store to be used for verifying peer certificate.
1552
+ attr_accessor :cert_store
1553
+
1554
+ # Sets or returns the available SSL ciphers.
1555
+ # See {OpenSSL::SSL::SSLContext#ciphers=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-ciphers-3D].
1556
+ attr_accessor :ciphers
1557
+
1558
+ # Sets or returns the extra X509 certificates to be added to the certificate chain.
1559
+ # See {OpenSSL::SSL::SSLContext#add_certificate}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-add_certificate].
1560
+ attr_accessor :extra_chain_cert
1561
+
1562
+ # Sets or returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
1563
+ attr_accessor :key
1564
+
1565
+ # Sets or returns the SSL timeout seconds.
1566
+ attr_accessor :ssl_timeout
1567
+
1568
+ # Sets or returns the SSL version.
1569
+ # See {OpenSSL::SSL::SSLContext#ssl_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-ssl_version-3D].
1570
+ attr_accessor :ssl_version
1571
+
1572
+ # Sets or returns the minimum SSL version.
1573
+ # See {OpenSSL::SSL::SSLContext#min_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-min_version-3D].
1574
+ attr_accessor :min_version
1575
+
1576
+ # Sets or returns the maximum SSL version.
1577
+ # See {OpenSSL::SSL::SSLContext#max_version=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-max_version-3D].
1578
+ attr_accessor :max_version
1579
+
1580
+ # Sets or returns the callback for the server certification verification.
1581
+ attr_accessor :verify_callback
1582
+
1583
+ # Sets or returns the maximum depth for the certificate chain verification.
1584
+ attr_accessor :verify_depth
1585
+
1586
+ # Sets or returns the flags for server the certification verification
1587
+ # at the beginning of the SSL/TLS session.
1588
+ # OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER are acceptable.
1589
+ attr_accessor :verify_mode
1590
+
1591
+ # Sets or returns whether to verify that the server certificate is valid
1592
+ # for the hostname.
1593
+ # See {OpenSSL::SSL::SSLContext#verify_hostname=}[https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#attribute-i-verify_mode].
1594
+ attr_accessor :verify_hostname
1595
+
1596
+ # Returns the X509 certificate chain (an array of strings)
1597
+ # for the session's socket peer,
1598
+ # or +nil+ if none.
1599
+ def peer_cert
1600
+ if not use_ssl? or not @socket
1601
+ return nil
1602
+ end
1603
+ @socket.io.peer_cert
1604
+ end
1605
+
1606
+ # Starts an \HTTP session.
1607
+ #
1608
+ # Without a block, returns +self+:
1609
+ #
1610
+ # http = Gem::Net::HTTP.new(hostname)
1611
+ # # => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>
1612
+ # http.start
1613
+ # # => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=true>
1614
+ # http.started? # => true
1615
+ # http.finish
1616
+ #
1617
+ # With a block, calls the block with +self+,
1618
+ # finishes the session when the block exits,
1619
+ # and returns the block's value:
1620
+ #
1621
+ # http.start do |http|
1622
+ # http
1623
+ # end
1624
+ # # => #<Gem::Net::HTTP jsonplaceholder.typicode.com:80 open=false>
1625
+ # http.started? # => false
1626
+ #
1627
+ def start # :yield: http
1628
+ raise IOError, 'HTTP session already opened' if @started
1629
+ if block_given?
1630
+ begin
1631
+ do_start
1632
+ return yield(self)
1633
+ ensure
1634
+ do_finish
1635
+ end
1636
+ end
1637
+ do_start
1638
+ self
1639
+ end
1640
+
1641
+ def do_start
1642
+ connect
1643
+ @started = true
1644
+ end
1645
+ private :do_start
1646
+
1647
+ def connect
1648
+ if use_ssl?
1649
+ # reference early to load OpenSSL before connecting,
1650
+ # as OpenSSL may take time to load.
1651
+ @ssl_context = OpenSSL::SSL::SSLContext.new
1652
+ end
1653
+
1654
+ if proxy? then
1655
+ conn_addr = proxy_address
1656
+ conn_port = proxy_port
1657
+ else
1658
+ conn_addr = conn_address
1659
+ conn_port = port
1660
+ end
1661
+
1662
+ debug "opening connection to #{conn_addr}:#{conn_port}..."
1663
+ s = Gem::Timeout.timeout(@open_timeout, Gem::Net::OpenTimeout) {
1664
+ begin
1665
+ TCPSocket.open(conn_addr, conn_port, @local_host, @local_port)
1666
+ rescue => e
1667
+ raise e, "Failed to open TCP connection to " +
1668
+ "#{conn_addr}:#{conn_port} (#{e.message})"
1669
+ end
1670
+ }
1671
+ s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
1672
+ debug "opened"
1673
+ if use_ssl?
1674
+ if proxy?
1675
+ if @proxy_use_ssl
1676
+ proxy_sock = OpenSSL::SSL::SSLSocket.new(s)
1677
+ ssl_socket_connect(proxy_sock, @open_timeout)
1678
+ else
1679
+ proxy_sock = s
1680
+ end
1681
+ proxy_sock = BufferedIO.new(proxy_sock, read_timeout: @read_timeout,
1682
+ write_timeout: @write_timeout,
1683
+ continue_timeout: @continue_timeout,
1684
+ debug_output: @debug_output)
1685
+ buf = +"CONNECT #{conn_address}:#{@port} HTTP/#{HTTPVersion}\r\n" \
1686
+ "Host: #{@address}:#{@port}\r\n"
1687
+ if proxy_user
1688
+ credential = ["#{proxy_user}:#{proxy_pass}"].pack('m0')
1689
+ buf << "Proxy-Authorization: Basic #{credential}\r\n"
1690
+ end
1691
+ buf << "\r\n"
1692
+ proxy_sock.write(buf)
1693
+ HTTPResponse.read_new(proxy_sock).value
1694
+ # assuming nothing left in buffers after successful CONNECT response
1695
+ end
1696
+
1697
+ ssl_parameters = Hash.new
1698
+ iv_list = instance_variables
1699
+ SSL_IVNAMES.each_with_index do |ivname, i|
1700
+ if iv_list.include?(ivname)
1701
+ value = instance_variable_get(ivname)
1702
+ unless value.nil?
1703
+ ssl_parameters[SSL_ATTRIBUTES[i]] = value
1704
+ end
1705
+ end
1706
+ end
1707
+ @ssl_context.set_params(ssl_parameters)
1708
+ unless @ssl_context.session_cache_mode.nil? # a dummy method on JRuby
1709
+ @ssl_context.session_cache_mode =
1710
+ OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
1711
+ OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
1712
+ end
1713
+ if @ssl_context.respond_to?(:session_new_cb) # not implemented under JRuby
1714
+ @ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess }
1715
+ end
1716
+
1717
+ # Still do the post_connection_check below even if connecting
1718
+ # to IP address
1719
+ verify_hostname = @ssl_context.verify_hostname
1720
+
1721
+ # Server Name Indication (SNI) RFC 3546/6066
1722
+ case @address
1723
+ when Gem::Resolv::IPv4::Regex, Gem::Resolv::IPv6::Regex
1724
+ # don't set SNI, as IP addresses in SNI is not valid
1725
+ # per RFC 6066, section 3.
1726
+
1727
+ # Avoid openssl warning
1728
+ @ssl_context.verify_hostname = false
1729
+ else
1730
+ ssl_host_address = @address
1731
+ end
1732
+
1733
+ debug "starting SSL for #{conn_addr}:#{conn_port}..."
1734
+ s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
1735
+ s.sync_close = true
1736
+ s.hostname = ssl_host_address if s.respond_to?(:hostname=) && ssl_host_address
1737
+
1738
+ if @ssl_session and
1739
+ Process.clock_gettime(Process::CLOCK_REALTIME) < @ssl_session.time.to_f + @ssl_session.timeout
1740
+ s.session = @ssl_session
1741
+ end
1742
+ ssl_socket_connect(s, @open_timeout)
1743
+ if (@ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE) && verify_hostname
1744
+ s.post_connection_check(@address)
1745
+ end
1746
+ debug "SSL established, protocol: #{s.ssl_version}, cipher: #{s.cipher[0]}"
1747
+ end
1748
+ @socket = BufferedIO.new(s, read_timeout: @read_timeout,
1749
+ write_timeout: @write_timeout,
1750
+ continue_timeout: @continue_timeout,
1751
+ debug_output: @debug_output)
1752
+ @last_communicated = nil
1753
+ on_connect
1754
+ rescue => exception
1755
+ if s
1756
+ debug "Conn close because of connect error #{exception}"
1757
+ s.close
1758
+ end
1759
+ raise
1760
+ end
1761
+ private :connect
1762
+
1763
+ def on_connect
1764
+ end
1765
+ private :on_connect
1766
+
1767
+ # Finishes the \HTTP session:
1768
+ #
1769
+ # http = Gem::Net::HTTP.new(hostname)
1770
+ # http.start
1771
+ # http.started? # => true
1772
+ # http.finish # => nil
1773
+ # http.started? # => false
1774
+ #
1775
+ # Raises IOError if not in a session.
1776
+ def finish
1777
+ raise IOError, 'HTTP session not yet started' unless started?
1778
+ do_finish
1779
+ end
1780
+
1781
+ def do_finish
1782
+ @started = false
1783
+ @socket.close if @socket
1784
+ @socket = nil
1785
+ end
1786
+ private :do_finish
1787
+
1788
+ #
1789
+ # proxy
1790
+ #
1791
+
1792
+ public
1793
+
1794
+ # no proxy
1795
+ @is_proxy_class = false
1796
+ @proxy_from_env = false
1797
+ @proxy_addr = nil
1798
+ @proxy_port = nil
1799
+ @proxy_user = nil
1800
+ @proxy_pass = nil
1801
+ @proxy_use_ssl = nil
1802
+
1803
+ # Creates an \HTTP proxy class which behaves like \Gem::Net::HTTP, but
1804
+ # performs all access via the specified proxy.
1805
+ #
1806
+ # This class is obsolete. You may pass these same parameters directly to
1807
+ # \Gem::Net::HTTP.new. See Gem::Net::HTTP.new for details of the arguments.
1808
+ def HTTP.Proxy(p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_use_ssl = nil) #:nodoc:
1809
+ return self unless p_addr
1810
+
1811
+ Class.new(self) {
1812
+ @is_proxy_class = true
1813
+
1814
+ if p_addr == :ENV then
1815
+ @proxy_from_env = true
1816
+ @proxy_address = nil
1817
+ @proxy_port = nil
1818
+ else
1819
+ @proxy_from_env = false
1820
+ @proxy_address = p_addr
1821
+ @proxy_port = p_port || default_port
1822
+ end
1823
+
1824
+ @proxy_user = p_user
1825
+ @proxy_pass = p_pass
1826
+ @proxy_use_ssl = p_use_ssl
1827
+ }
1828
+ end
1829
+
1830
+ class << HTTP
1831
+ # Returns true if self is a class which was created by HTTP::Proxy.
1832
+ def proxy_class?
1833
+ defined?(@is_proxy_class) ? @is_proxy_class : false
1834
+ end
1835
+
1836
+ # Returns the address of the proxy host, or +nil+ if none;
1837
+ # see Gem::Net::HTTP@Proxy+Server.
1838
+ attr_reader :proxy_address
1839
+
1840
+ # Returns the port number of the proxy host, or +nil+ if none;
1841
+ # see Gem::Net::HTTP@Proxy+Server.
1842
+ attr_reader :proxy_port
1843
+
1844
+ # Returns the user name for accessing the proxy, or +nil+ if none;
1845
+ # see Gem::Net::HTTP@Proxy+Server.
1846
+ attr_reader :proxy_user
1847
+
1848
+ # Returns the password for accessing the proxy, or +nil+ if none;
1849
+ # see Gem::Net::HTTP@Proxy+Server.
1850
+ attr_reader :proxy_pass
1851
+
1852
+ # Use SSL when talking to the proxy. If Gem::Net::HTTP does not use a proxy, nil.
1853
+ attr_reader :proxy_use_ssl
1854
+ end
1855
+
1856
+ # Returns +true+ if a proxy server is defined, +false+ otherwise;
1857
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1858
+ def proxy?
1859
+ !!(@proxy_from_env ? proxy_uri : @proxy_address)
1860
+ end
1861
+
1862
+ # Returns +true+ if the proxy server is defined in the environment,
1863
+ # +false+ otherwise;
1864
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1865
+ def proxy_from_env?
1866
+ @proxy_from_env
1867
+ end
1868
+
1869
+ # The proxy URI determined from the environment for this connection.
1870
+ def proxy_uri # :nodoc:
1871
+ return if @proxy_uri == false
1872
+ @proxy_uri ||= Gem::URI::HTTP.new(
1873
+ "http", nil, address, port, nil, nil, nil, nil, nil
1874
+ ).find_proxy || false
1875
+ @proxy_uri || nil
1876
+ end
1877
+
1878
+ # Returns the address of the proxy server, if defined, +nil+ otherwise;
1879
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1880
+ def proxy_address
1881
+ if @proxy_from_env then
1882
+ proxy_uri&.hostname
1883
+ else
1884
+ @proxy_address
1885
+ end
1886
+ end
1887
+
1888
+ # Returns the port number of the proxy server, if defined, +nil+ otherwise;
1889
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1890
+ def proxy_port
1891
+ if @proxy_from_env then
1892
+ proxy_uri&.port
1893
+ else
1894
+ @proxy_port
1895
+ end
1896
+ end
1897
+
1898
+ # Returns the user name of the proxy server, if defined, +nil+ otherwise;
1899
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1900
+ def proxy_user
1901
+ if @proxy_from_env
1902
+ user = proxy_uri&.user
1903
+ unescape(user) if user
1904
+ else
1905
+ @proxy_user
1906
+ end
1907
+ end
1908
+
1909
+ # Returns the password of the proxy server, if defined, +nil+ otherwise;
1910
+ # see {Proxy Server}[rdoc-ref:Gem::Net::HTTP@Proxy+Server].
1911
+ def proxy_pass
1912
+ if @proxy_from_env
1913
+ pass = proxy_uri&.password
1914
+ unescape(pass) if pass
1915
+ else
1916
+ @proxy_pass
1917
+ end
1918
+ end
1919
+
1920
+ alias proxyaddr proxy_address #:nodoc: obsolete
1921
+ alias proxyport proxy_port #:nodoc: obsolete
1922
+
1923
+ private
1924
+
1925
+ def unescape(value)
1926
+ require 'cgi/util'
1927
+ CGI.unescape(value)
1928
+ end
1929
+
1930
+ # without proxy, obsolete
1931
+
1932
+ def conn_address # :nodoc:
1933
+ @ipaddr || address()
1934
+ end
1935
+
1936
+ def conn_port # :nodoc:
1937
+ port()
1938
+ end
1939
+
1940
+ def edit_path(path)
1941
+ if proxy?
1942
+ if path.start_with?("ftp://") || use_ssl?
1943
+ path
1944
+ else
1945
+ "http://#{addr_port}#{path}"
1946
+ end
1947
+ else
1948
+ path
1949
+ end
1950
+ end
1951
+
1952
+ #
1953
+ # HTTP operations
1954
+ #
1955
+
1956
+ public
1957
+
1958
+ # :call-seq:
1959
+ # get(path, initheader = nil) {|res| ... }
1960
+ #
1961
+ # Sends a GET request to the server;
1962
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
1963
+ #
1964
+ # The request is based on the Gem::Net::HTTP::Get object
1965
+ # created from string +path+ and initial headers hash +initheader+.
1966
+ #
1967
+ # With a block given, calls the block with the response body:
1968
+ #
1969
+ # http = Gem::Net::HTTP.new(hostname)
1970
+ # http.get('/todos/1') do |res|
1971
+ # p res
1972
+ # end # => #<Gem::Net::HTTPOK 200 OK readbody=true>
1973
+ #
1974
+ # Output:
1975
+ #
1976
+ # "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}"
1977
+ #
1978
+ # With no block given, simply returns the response object:
1979
+ #
1980
+ # http.get('/') # => #<Gem::Net::HTTPOK 200 OK readbody=true>
1981
+ #
1982
+ # Related:
1983
+ #
1984
+ # - Gem::Net::HTTP::Get: request class for \HTTP method GET.
1985
+ # - Gem::Net::HTTP.get: sends GET request, returns response body.
1986
+ #
1987
+ def get(path, initheader = nil, dest = nil, &block) # :yield: +body_segment+
1988
+ res = nil
1989
+
1990
+ request(Get.new(path, initheader)) {|r|
1991
+ r.read_body dest, &block
1992
+ res = r
1993
+ }
1994
+ res
1995
+ end
1996
+
1997
+ # Sends a HEAD request to the server;
1998
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
1999
+ #
2000
+ # The request is based on the Gem::Net::HTTP::Head object
2001
+ # created from string +path+ and initial headers hash +initheader+:
2002
+ #
2003
+ # res = http.head('/todos/1') # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2004
+ # res.body # => nil
2005
+ # res.to_hash.take(3)
2006
+ # # =>
2007
+ # [["date", ["Wed, 15 Feb 2023 15:25:42 GMT"]],
2008
+ # ["content-type", ["application/json; charset=utf-8"]],
2009
+ # ["connection", ["close"]]]
2010
+ #
2011
+ def head(path, initheader = nil)
2012
+ request(Head.new(path, initheader))
2013
+ end
2014
+
2015
+ # :call-seq:
2016
+ # post(path, data, initheader = nil) {|res| ... }
2017
+ #
2018
+ # Sends a POST request to the server;
2019
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2020
+ #
2021
+ # The request is based on the Gem::Net::HTTP::Post object
2022
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
2023
+ #
2024
+ # With a block given, calls the block with the response body:
2025
+ #
2026
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2027
+ # http = Gem::Net::HTTP.new(hostname)
2028
+ # http.post('/todos', data) do |res|
2029
+ # p res
2030
+ # end # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2031
+ #
2032
+ # Output:
2033
+ #
2034
+ # "{\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\",\n \"id\": 201\n}"
2035
+ #
2036
+ # With no block given, simply returns the response object:
2037
+ #
2038
+ # http.post('/todos', data) # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2039
+ #
2040
+ # Related:
2041
+ #
2042
+ # - Gem::Net::HTTP::Post: request class for \HTTP method POST.
2043
+ # - Gem::Net::HTTP.post: sends POST request, returns response body.
2044
+ #
2045
+ def post(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
2046
+ send_entity(path, data, initheader, dest, Post, &block)
2047
+ end
2048
+
2049
+ # :call-seq:
2050
+ # patch(path, data, initheader = nil) {|res| ... }
2051
+ #
2052
+ # Sends a PATCH request to the server;
2053
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2054
+ #
2055
+ # The request is based on the Gem::Net::HTTP::Patch object
2056
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
2057
+ #
2058
+ # With a block given, calls the block with the response body:
2059
+ #
2060
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2061
+ # http = Gem::Net::HTTP.new(hostname)
2062
+ # http.patch('/todos/1', data) do |res|
2063
+ # p res
2064
+ # end # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2065
+ #
2066
+ # Output:
2067
+ #
2068
+ # "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false,\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\"\n}"
2069
+ #
2070
+ # With no block given, simply returns the response object:
2071
+ #
2072
+ # http.patch('/todos/1', data) # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2073
+ #
2074
+ def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+
2075
+ send_entity(path, data, initheader, dest, Patch, &block)
2076
+ end
2077
+
2078
+ # Sends a PUT request to the server;
2079
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2080
+ #
2081
+ # The request is based on the Gem::Net::HTTP::Put object
2082
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
2083
+ #
2084
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2085
+ # http = Gem::Net::HTTP.new(hostname)
2086
+ # http.put('/todos/1', data) # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2087
+ #
2088
+ # Related:
2089
+ #
2090
+ # - Gem::Net::HTTP::Put: request class for \HTTP method PUT.
2091
+ # - Gem::Net::HTTP.put: sends PUT request, returns response body.
2092
+ #
2093
+ def put(path, data, initheader = nil)
2094
+ request(Put.new(path, initheader), data)
2095
+ end
2096
+
2097
+ # Sends a PROPPATCH request to the server;
2098
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2099
+ #
2100
+ # The request is based on the Gem::Net::HTTP::Proppatch object
2101
+ # created from string +path+, string +body+, and initial headers hash +initheader+.
2102
+ #
2103
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2104
+ # http = Gem::Net::HTTP.new(hostname)
2105
+ # http.proppatch('/todos/1', data)
2106
+ #
2107
+ def proppatch(path, body, initheader = nil)
2108
+ request(Proppatch.new(path, initheader), body)
2109
+ end
2110
+
2111
+ # Sends a LOCK request to the server;
2112
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2113
+ #
2114
+ # The request is based on the Gem::Net::HTTP::Lock object
2115
+ # created from string +path+, string +body+, and initial headers hash +initheader+.
2116
+ #
2117
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2118
+ # http = Gem::Net::HTTP.new(hostname)
2119
+ # http.lock('/todos/1', data)
2120
+ #
2121
+ def lock(path, body, initheader = nil)
2122
+ request(Lock.new(path, initheader), body)
2123
+ end
2124
+
2125
+ # Sends an UNLOCK request to the server;
2126
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2127
+ #
2128
+ # The request is based on the Gem::Net::HTTP::Unlock object
2129
+ # created from string +path+, string +body+, and initial headers hash +initheader+.
2130
+ #
2131
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2132
+ # http = Gem::Net::HTTP.new(hostname)
2133
+ # http.unlock('/todos/1', data)
2134
+ #
2135
+ def unlock(path, body, initheader = nil)
2136
+ request(Unlock.new(path, initheader), body)
2137
+ end
2138
+
2139
+ # Sends an Options request to the server;
2140
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2141
+ #
2142
+ # The request is based on the Gem::Net::HTTP::Options object
2143
+ # created from string +path+ and initial headers hash +initheader+.
2144
+ #
2145
+ # http = Gem::Net::HTTP.new(hostname)
2146
+ # http.options('/')
2147
+ #
2148
+ def options(path, initheader = nil)
2149
+ request(Options.new(path, initheader))
2150
+ end
2151
+
2152
+ # Sends a PROPFIND request to the server;
2153
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2154
+ #
2155
+ # The request is based on the Gem::Net::HTTP::Propfind object
2156
+ # created from string +path+, string +body+, and initial headers hash +initheader+.
2157
+ #
2158
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2159
+ # http = Gem::Net::HTTP.new(hostname)
2160
+ # http.propfind('/todos/1', data)
2161
+ #
2162
+ def propfind(path, body = nil, initheader = {'Depth' => '0'})
2163
+ request(Propfind.new(path, initheader), body)
2164
+ end
2165
+
2166
+ # Sends a DELETE request to the server;
2167
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2168
+ #
2169
+ # The request is based on the Gem::Net::HTTP::Delete object
2170
+ # created from string +path+ and initial headers hash +initheader+.
2171
+ #
2172
+ # http = Gem::Net::HTTP.new(hostname)
2173
+ # http.delete('/todos/1')
2174
+ #
2175
+ def delete(path, initheader = {'Depth' => 'Infinity'})
2176
+ request(Delete.new(path, initheader))
2177
+ end
2178
+
2179
+ # Sends a MOVE request to the server;
2180
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2181
+ #
2182
+ # The request is based on the Gem::Net::HTTP::Move object
2183
+ # created from string +path+ and initial headers hash +initheader+.
2184
+ #
2185
+ # http = Gem::Net::HTTP.new(hostname)
2186
+ # http.move('/todos/1')
2187
+ #
2188
+ def move(path, initheader = nil)
2189
+ request(Move.new(path, initheader))
2190
+ end
2191
+
2192
+ # Sends a COPY request to the server;
2193
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2194
+ #
2195
+ # The request is based on the Gem::Net::HTTP::Copy object
2196
+ # created from string +path+ and initial headers hash +initheader+.
2197
+ #
2198
+ # http = Gem::Net::HTTP.new(hostname)
2199
+ # http.copy('/todos/1')
2200
+ #
2201
+ def copy(path, initheader = nil)
2202
+ request(Copy.new(path, initheader))
2203
+ end
2204
+
2205
+ # Sends a MKCOL request to the server;
2206
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2207
+ #
2208
+ # The request is based on the Gem::Net::HTTP::Mkcol object
2209
+ # created from string +path+, string +body+, and initial headers hash +initheader+.
2210
+ #
2211
+ # data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
2212
+ # http.mkcol('/todos/1', data)
2213
+ # http = Gem::Net::HTTP.new(hostname)
2214
+ #
2215
+ def mkcol(path, body = nil, initheader = nil)
2216
+ request(Mkcol.new(path, initheader), body)
2217
+ end
2218
+
2219
+ # Sends a TRACE request to the server;
2220
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2221
+ #
2222
+ # The request is based on the Gem::Net::HTTP::Trace object
2223
+ # created from string +path+ and initial headers hash +initheader+.
2224
+ #
2225
+ # http = Gem::Net::HTTP.new(hostname)
2226
+ # http.trace('/todos/1')
2227
+ #
2228
+ def trace(path, initheader = nil)
2229
+ request(Trace.new(path, initheader))
2230
+ end
2231
+
2232
+ # Sends a GET request to the server;
2233
+ # forms the response into a Gem::Net::HTTPResponse object.
2234
+ #
2235
+ # The request is based on the Gem::Net::HTTP::Get object
2236
+ # created from string +path+ and initial headers hash +initheader+.
2237
+ #
2238
+ # With no block given, returns the response object:
2239
+ #
2240
+ # http = Gem::Net::HTTP.new(hostname)
2241
+ # http.request_get('/todos') # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2242
+ #
2243
+ # With a block given, calls the block with the response object
2244
+ # and returns the response object:
2245
+ #
2246
+ # http.request_get('/todos') do |res|
2247
+ # p res
2248
+ # end # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2249
+ #
2250
+ # Output:
2251
+ #
2252
+ # #<Gem::Net::HTTPOK 200 OK readbody=false>
2253
+ #
2254
+ def request_get(path, initheader = nil, &block) # :yield: +response+
2255
+ request(Get.new(path, initheader), &block)
2256
+ end
2257
+
2258
+ # Sends a HEAD request to the server;
2259
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2260
+ #
2261
+ # The request is based on the Gem::Net::HTTP::Head object
2262
+ # created from string +path+ and initial headers hash +initheader+.
2263
+ #
2264
+ # http = Gem::Net::HTTP.new(hostname)
2265
+ # http.head('/todos/1') # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2266
+ #
2267
+ def request_head(path, initheader = nil, &block)
2268
+ request(Head.new(path, initheader), &block)
2269
+ end
2270
+
2271
+ # Sends a POST request to the server;
2272
+ # forms the response into a Gem::Net::HTTPResponse object.
2273
+ #
2274
+ # The request is based on the Gem::Net::HTTP::Post object
2275
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
2276
+ #
2277
+ # With no block given, returns the response object:
2278
+ #
2279
+ # http = Gem::Net::HTTP.new(hostname)
2280
+ # http.post('/todos', 'xyzzy')
2281
+ # # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2282
+ #
2283
+ # With a block given, calls the block with the response body
2284
+ # and returns the response object:
2285
+ #
2286
+ # http.post('/todos', 'xyzzy') do |res|
2287
+ # p res
2288
+ # end # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2289
+ #
2290
+ # Output:
2291
+ #
2292
+ # "{\n \"xyzzy\": \"\",\n \"id\": 201\n}"
2293
+ #
2294
+ def request_post(path, data, initheader = nil, &block) # :yield: +response+
2295
+ request Post.new(path, initheader), data, &block
2296
+ end
2297
+
2298
+ # Sends a PUT request to the server;
2299
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2300
+ #
2301
+ # The request is based on the Gem::Net::HTTP::Put object
2302
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
2303
+ #
2304
+ # http = Gem::Net::HTTP.new(hostname)
2305
+ # http.put('/todos/1', 'xyzzy')
2306
+ # # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2307
+ #
2308
+ def request_put(path, data, initheader = nil, &block) #:nodoc:
2309
+ request Put.new(path, initheader), data, &block
2310
+ end
2311
+
2312
+ alias get2 request_get #:nodoc: obsolete
2313
+ alias head2 request_head #:nodoc: obsolete
2314
+ alias post2 request_post #:nodoc: obsolete
2315
+ alias put2 request_put #:nodoc: obsolete
2316
+
2317
+ # Sends an \HTTP request to the server;
2318
+ # returns an instance of a subclass of Gem::Net::HTTPResponse.
2319
+ #
2320
+ # The request is based on the Gem::Net::HTTPRequest object
2321
+ # created from string +path+, string +data+, and initial headers hash +header+.
2322
+ # That object is an instance of the
2323
+ # {subclass of Gem::Net::HTTPRequest}[rdoc-ref:Gem::Net::HTTPRequest@Request+Subclasses],
2324
+ # that corresponds to the given uppercase string +name+,
2325
+ # which must be
2326
+ # an {HTTP request method}[https://en.wikipedia.org/wiki/HTTP#Request_methods]
2327
+ # or a {WebDAV request method}[https://en.wikipedia.org/wiki/WebDAV#Implementation].
2328
+ #
2329
+ # Examples:
2330
+ #
2331
+ # http = Gem::Net::HTTP.new(hostname)
2332
+ # http.send_request('GET', '/todos/1')
2333
+ # # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2334
+ # http.send_request('POST', '/todos', 'xyzzy')
2335
+ # # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2336
+ #
2337
+ def send_request(name, path, data = nil, header = nil)
2338
+ has_response_body = name != 'HEAD'
2339
+ r = HTTPGenericRequest.new(name,(data ? true : false),has_response_body,path,header)
2340
+ request r, data
2341
+ end
2342
+
2343
+ # Sends the given request +req+ to the server;
2344
+ # forms the response into a Gem::Net::HTTPResponse object.
2345
+ #
2346
+ # The given +req+ must be an instance of a
2347
+ # {subclass of Gem::Net::HTTPRequest}[rdoc-ref:Gem::Net::HTTPRequest@Request+Subclasses].
2348
+ # Argument +body+ should be given only if needed for the request.
2349
+ #
2350
+ # With no block given, returns the response object:
2351
+ #
2352
+ # http = Gem::Net::HTTP.new(hostname)
2353
+ #
2354
+ # req = Gem::Net::HTTP::Get.new('/todos/1')
2355
+ # http.request(req)
2356
+ # # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2357
+ #
2358
+ # req = Gem::Net::HTTP::Post.new('/todos')
2359
+ # http.request(req, 'xyzzy')
2360
+ # # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2361
+ #
2362
+ # With a block given, calls the block with the response and returns the response:
2363
+ #
2364
+ # req = Gem::Net::HTTP::Get.new('/todos/1')
2365
+ # http.request(req) do |res|
2366
+ # p res
2367
+ # end # => #<Gem::Net::HTTPOK 200 OK readbody=true>
2368
+ #
2369
+ # Output:
2370
+ #
2371
+ # #<Gem::Net::HTTPOK 200 OK readbody=false>
2372
+ #
2373
+ def request(req, body = nil, &block) # :yield: +response+
2374
+ unless started?
2375
+ start {
2376
+ req['connection'] ||= 'close'
2377
+ return request(req, body, &block)
2378
+ }
2379
+ end
2380
+ if proxy_user()
2381
+ req.proxy_basic_auth proxy_user(), proxy_pass() unless use_ssl?
2382
+ end
2383
+ req.set_body_internal body
2384
+ res = transport_request(req, &block)
2385
+ if sspi_auth?(res)
2386
+ sspi_auth(req)
2387
+ res = transport_request(req, &block)
2388
+ end
2389
+ res
2390
+ end
2391
+
2392
+ private
2393
+
2394
+ # Executes a request which uses a representation
2395
+ # and returns its body.
2396
+ def send_entity(path, data, initheader, dest, type, &block)
2397
+ res = nil
2398
+ request(type.new(path, initheader), data) {|r|
2399
+ r.read_body dest, &block
2400
+ res = r
2401
+ }
2402
+ res
2403
+ end
2404
+
2405
+ IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
2406
+
2407
+ def transport_request(req)
2408
+ count = 0
2409
+ begin
2410
+ begin_transport req
2411
+ res = catch(:response) {
2412
+ begin
2413
+ req.exec @socket, @curr_http_version, edit_path(req.path)
2414
+ rescue Errno::EPIPE
2415
+ # Failure when writing full request, but we can probably
2416
+ # still read the received response.
2417
+ end
2418
+
2419
+ begin
2420
+ res = HTTPResponse.read_new(@socket)
2421
+ res.decode_content = req.decode_content
2422
+ res.body_encoding = @response_body_encoding
2423
+ res.ignore_eof = @ignore_eof
2424
+ end while res.kind_of?(HTTPInformation)
2425
+
2426
+ res.uri = req.uri
2427
+
2428
+ res
2429
+ }
2430
+ res.reading_body(@socket, req.response_body_permitted?) {
2431
+ if block_given?
2432
+ count = max_retries # Don't restart in the middle of a download
2433
+ yield res
2434
+ end
2435
+ }
2436
+ rescue Gem::Net::OpenTimeout
2437
+ raise
2438
+ rescue Gem::Net::ReadTimeout, IOError, EOFError,
2439
+ Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, Errno::ETIMEDOUT,
2440
+ # avoid a dependency on OpenSSL
2441
+ defined?(OpenSSL::SSL) ? OpenSSL::SSL::SSLError : IOError,
2442
+ Gem::Timeout::Error => exception
2443
+ if count < max_retries && IDEMPOTENT_METHODS_.include?(req.method)
2444
+ count += 1
2445
+ @socket.close if @socket
2446
+ debug "Conn close because of error #{exception}, and retry"
2447
+ retry
2448
+ end
2449
+ debug "Conn close because of error #{exception}"
2450
+ @socket.close if @socket
2451
+ raise
2452
+ end
2453
+
2454
+ end_transport req, res
2455
+ res
2456
+ rescue => exception
2457
+ debug "Conn close because of error #{exception}"
2458
+ @socket.close if @socket
2459
+ raise exception
2460
+ end
2461
+
2462
+ def begin_transport(req)
2463
+ if @socket.closed?
2464
+ connect
2465
+ elsif @last_communicated
2466
+ if @last_communicated + @keep_alive_timeout < Process.clock_gettime(Process::CLOCK_MONOTONIC)
2467
+ debug 'Conn close because of keep_alive_timeout'
2468
+ @socket.close
2469
+ connect
2470
+ elsif @socket.io.to_io.wait_readable(0) && @socket.eof?
2471
+ debug "Conn close because of EOF"
2472
+ @socket.close
2473
+ connect
2474
+ end
2475
+ end
2476
+
2477
+ if not req.response_body_permitted? and @close_on_empty_response
2478
+ req['connection'] ||= 'close'
2479
+ end
2480
+
2481
+ req.update_uri address, port, use_ssl?
2482
+ req['host'] ||= addr_port()
2483
+ end
2484
+
2485
+ def end_transport(req, res)
2486
+ @curr_http_version = res.http_version
2487
+ @last_communicated = nil
2488
+ if @socket.closed?
2489
+ debug 'Conn socket closed'
2490
+ elsif not res.body and @close_on_empty_response
2491
+ debug 'Conn close'
2492
+ @socket.close
2493
+ elsif keep_alive?(req, res)
2494
+ debug 'Conn keep-alive'
2495
+ @last_communicated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
2496
+ else
2497
+ debug 'Conn close'
2498
+ @socket.close
2499
+ end
2500
+ end
2501
+
2502
+ def keep_alive?(req, res)
2503
+ return false if req.connection_close?
2504
+ if @curr_http_version <= '1.0'
2505
+ res.connection_keep_alive?
2506
+ else # HTTP/1.1 or later
2507
+ not res.connection_close?
2508
+ end
2509
+ end
2510
+
2511
+ def sspi_auth?(res)
2512
+ return false unless @sspi_enabled
2513
+ if res.kind_of?(HTTPProxyAuthenticationRequired) and
2514
+ proxy? and res["Proxy-Authenticate"].include?("Negotiate")
2515
+ begin
2516
+ require 'win32/sspi'
2517
+ true
2518
+ rescue LoadError
2519
+ false
2520
+ end
2521
+ else
2522
+ false
2523
+ end
2524
+ end
2525
+
2526
+ def sspi_auth(req)
2527
+ n = Win32::SSPI::NegotiateAuth.new
2528
+ req["Proxy-Authorization"] = "Negotiate #{n.get_initial_token}"
2529
+ # Some versions of ISA will close the connection if this isn't present.
2530
+ req["Connection"] = "Keep-Alive"
2531
+ req["Proxy-Connection"] = "Keep-Alive"
2532
+ res = transport_request(req)
2533
+ authphrase = res["Proxy-Authenticate"] or return res
2534
+ req["Proxy-Authorization"] = "Negotiate #{n.complete_authentication(authphrase)}"
2535
+ rescue => err
2536
+ raise HTTPAuthenticationError.new('HTTP authentication failed', err)
2537
+ end
2538
+
2539
+ #
2540
+ # utils
2541
+ #
2542
+
2543
+ private
2544
+
2545
+ def addr_port
2546
+ addr = address
2547
+ addr = "[#{addr}]" if addr.include?(":")
2548
+ default_port = use_ssl? ? HTTP.https_default_port : HTTP.http_default_port
2549
+ default_port == port ? addr : "#{addr}:#{port}"
2550
+ end
2551
+
2552
+ # Adds a message to debugging output
2553
+ def debug(msg)
2554
+ return unless @debug_output
2555
+ @debug_output << msg
2556
+ @debug_output << "\n"
2557
+ end
2558
+
2559
+ alias_method :D, :debug
2560
+ end
2561
+
2562
+ # for backward compatibility until Ruby 3.5
2563
+ # https://bugs.ruby-lang.org/issues/20900
2564
+ # https://github.com/bblimke/webmock/pull/1081
2565
+ HTTPSession = HTTP
2566
+ deprecate_constant :HTTPSession
2567
+ end
2568
+
2569
+ require_relative 'http/exceptions'
2570
+
2571
+ require_relative 'http/header'
2572
+
2573
+ require_relative 'http/generic_request'
2574
+ require_relative 'http/request'
2575
+ require_relative 'http/requests'
2576
+
2577
+ require_relative 'http/response'
2578
+ require_relative 'http/responses'
2579
+
2580
+ require_relative 'http/proxy_delta'