lib/httpx/session.rb in httpx-0.15.4 vs lib/httpx/session.rb in httpx-0.16.0

- old
+ new

@@ -13,12 +13,10 @@ @persistent = @options.persistent wrap(&blk) if block_given? end def wrap - return unless block_given? - begin prev_persistent = @persistent @persistent = true yield self ensure @@ -29,10 +27,12 @@ def close(*args) pool.close(*args) end def request(*args, **options) + raise ArgumentError, "must perform at least one request" if args.empty? + requests = args.first.is_a?(Request) ? args : build_requests(*args, options) responses = send_requests(*requests, options) return responses.first if responses.size == 1 responses @@ -245,13 +245,12 @@ # raise Error, "Cannot add a plugin to a frozen config" if frozen? pl = Plugins.load_plugin(pl) if pl.is_a?(Symbol) 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 include(pl::InstanceMethods) if defined?(pl::InstanceMethods) extend(pl::ClassMethods) if defined?(pl::ClassMethods) opts = @default_options @@ -264,28 +263,40 @@ opts.request_body_class.__send__(:include, pl::RequestBodyMethods) if defined?(pl::RequestBodyMethods) 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) + if defined?(pl::OptionsMethods) + opts.options_class.__send__(:include, pl::OptionsMethods) + + (pl::OptionsMethods.instance_methods - Object.instance_methods).each do |meth| + opts.options_class.method_added(meth) + end + @default_options = opts.options_class.new(opts) + end + + @default_options = pl.extra_options(@default_options) if pl.respond_to?(:extra_options) + @default_options = @default_options.merge(options) if options + 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 = pl.extra_options(@default_options) if pl.respond_to?(:extra_options) + @default_options = @default_options.merge(options) if options @default_options.freeze end self end # :nocov: def plugins(pls) warn ":#{__method__} is deprecated, use :plugin instead" - pls.each do |pl, *args| - plugin(pl, *args) + pls.each do |pl| + plugin(pl) end self end # :nocov: end