lib/httpx/session.rb in httpx-0.9.0 vs lib/httpx/session.rb in httpx-0.10.0
- old
+ new
@@ -64,11 +64,12 @@
def fetch_response(request, _, _)
@responses.delete(request)
end
def find_connection(request, connections, options)
- uri = URI(request.uri)
+ uri = request.uri
+
connection = pool.find_connection(uri, options) || build_connection(uri, options)
unless connections.nil? || connections.include?(connection)
connections << connection
set_connection_callbacks(connection, connections, options)
end
@@ -133,14 +134,14 @@
when 1
reqs = args.first
reqs.map do |verb, uri, opts = EMPTY_HASH|
build_request(verb, uri, request_options.merge(opts))
end
- when 2, 3
+ when 2
verb, uris = args
if uris.respond_to?(:each)
- uris.map do |uri, **opts|
+ uris.enum_for(:each).map do |uri, opts = EMPTY_HASH|
build_request(verb, uri, request_options.merge(opts))
end
else
[build_request(verb, uris, request_options)]
end
@@ -187,19 +188,17 @@
responses = []
begin
# guarantee ordered responses
loop do
- begin
- request = requests.first
- pool.next_tick until (response = fetch_response(request, connections, request_options))
+ request = requests.first
+ pool.next_tick until (response = fetch_response(request, connections, request_options))
- responses << response
- requests.shift
+ responses << response
+ requests.shift
- break if requests.empty? || pool.empty?
- end
+ break if requests.empty? || pool.empty?
end
responses
ensure
close(connections) unless @persistent
end
@@ -219,11 +218,11 @@
end
def plugin(pl, options = nil, &block)
# raise Error, "Cannot add a plugin to a frozen config" if frozen?
pl = Plugins.load_plugin(pl) if pl.is_a?(Symbol)
- unless @plugins.include?(pl)
+ if !@plugins.include?(pl)
@plugins << pl
pl.load_dependencies(self, &block) if pl.respond_to?(:load_dependencies)
@default_options = @default_options.dup
@default_options = pl.extra_options(@default_options, &block) if pl.respond_to?(:extra_options)
@default_options = @default_options.merge(options) if options
@@ -242,9 +241,16 @@
opts.request_body_class.extend(pl::RequestBodyClassMethods) if defined?(pl::RequestBodyClassMethods)
opts.response_body_class.__send__(:include, pl::ResponseBodyMethods) if defined?(pl::ResponseBodyMethods)
opts.response_body_class.extend(pl::ResponseBodyClassMethods) if defined?(pl::ResponseBodyClassMethods)
opts.connection_class.__send__(:include, pl::ConnectionMethods) if defined?(pl::ConnectionMethods)
pl.configure(self, &block) if pl.respond_to?(:configure)
+
+ @default_options.freeze
+ elsif options
+ # this can happen when two plugins are loaded, an one of them calls the other under the hood,
+ # albeit changing some default.
+ @default_options = @default_options.dup
+ @default_options = @default_options.merge(options)
@default_options.freeze
end
self
end