deprecating the .plugins, as it's not compatible with sending plugin options

This commit is contained in:
HoneyryderChuck 2020-02-09 00:23:05 +00:00
parent 4724cbee33
commit 4451218300
3 changed files with 14 additions and 4 deletions

View File

@ -28,13 +28,20 @@ module HTTPX
branch(default_options).wrap(&blk)
end
def plugin(*plugins)
def plugin(*args, **opts)
klass = is_a?(Session) ? self.class : Session
klass = Class.new(klass)
klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
klass.plugins(plugins).new
klass.plugin(*args, **opts).new
end
# deprecated
def plugins(*args, **opts)
klass = is_a?(Session) ? self.class : Session
klass = Class.new(klass)
klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
klass.plugins(*args, **opts).new
end
alias_method :plugins, :plugin
def with(options, &blk)
branch(default_options.merge(options), &blk)

View File

@ -251,12 +251,15 @@ module HTTPX
self
end
# :nocov:
def plugins(pls)
warn ":#{__method__} is deprecated, use :plugin instead"
pls.each do |pl, *args|
plugin(pl, *args)
end
self
end
# :nocov:
end
plugin(:proxy) unless ENV.grep(/https?_proxy$/i).empty?

View File

@ -43,7 +43,7 @@ module Requests
end
def test_plugin_cookies_follow
session = HTTPX.plugins(:follow_redirects, :cookies)
session = HTTPX.plugin(:follow_redirects).plugin(:cookies)
session_cookies = { "a" => "b", "c" => "d" }
session_uri = cookies_set_uri(session_cookies)