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