remove deprecated APIs

This commit is contained in:
HoneyryderChuck 2023-06-23 13:15:40 +01:00
parent f0f6b5f7e2
commit 8cd1aac99c
13 changed files with 18 additions and 141 deletions

View File

@ -53,14 +53,6 @@ module HTTPX
end
end
# :nocov:
def self.const_missing(const_name)
super unless const_name == :Client
warn "DEPRECATION WARNING: the class #{self}::Client is deprecated. Use #{self}::Session instead."
Session
end
# :nocov:
extend Chainable
end

View File

@ -27,18 +27,6 @@ module HTTPX
branch(default_options).request(*args, **options)
end
# :nocov:
def timeout(**args)
warn ":#{__method__} is deprecated, use :with_timeout instead"
with(timeout: args)
end
def headers(headers)
warn ":#{__method__} is deprecated, use :with_headers instead"
with(headers: headers)
end
# :nocov:
def accept(type)
with(headers: { "accept" => String(type) })
end
@ -54,17 +42,6 @@ module HTTPX
klass.plugin(pl, options, &blk).new
end
# deprecated
# :nocov:
def plugins(pls)
warn ":#{__method__} is deprecated, use :plugin instead"
klass = is_a?(S) ? self.class : Session
klass = Class.new(klass)
klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
klass.plugins(pls).new
end
# :nocov:
def with(options, &blk)
branch(default_options.merge(options), &blk)
end

View File

@ -27,14 +27,7 @@ module HTTPX
@keep_open = true
@state = :connected
else
if @options.transport_options
# :nocov:
warn ":transport_options is deprecated, use :addresses instead"
@path = @options.transport_options[:path]
# :nocov:
else
@path = addresses.first
end
@path = addresses.first
end
@io ||= build_socket
end

View File

@ -52,7 +52,6 @@ module HTTPX
:connection_class => Class.new(Connection),
:options_class => Class.new(self),
:transport => nil,
:transport_options => nil,
:addresses => nil,
:persistent => false,
:resolver_class => (ENV["HTTPX_RESOLVER"] || :native).to_sym,
@ -78,34 +77,6 @@ module HTTPX
attr_reader(optname)
end
def def_option(optname, *args, &block)
if args.empty? && !block
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
def option_#{optname}(v); v; end # def option_smth(v); v; end
OUT
return
end
deprecated_def_option(optname, *args, &block)
end
def deprecated_def_option(optname, layout = nil, &interpreter)
warn "DEPRECATION WARNING: using `def_option(#{optname})` for setting options is deprecated. " \
"Define module OptionsMethods and `def option_#{optname}(val)` instead."
if layout
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
def option_#{optname}(value) # def option_origin(v)
#{layout} # URI(v)
end # end
OUT
elsif interpreter
define_method(:"option_#{optname}") do |value|
instance_exec(value, &interpreter)
end
end
end
end
def initialize(options = {})
@ -135,14 +106,7 @@ module HTTPX
end
def option_timeout(value)
timeouts = Hash[value]
if timeouts.key?(:loop_timeout)
warn ":loop_timeout is deprecated, use :operation_timeout instead"
timeouts[:operation_timeout] = timeouts.delete(:loop_timeout)
end
timeouts
Hash[value]
end
def option_max_concurrent_requests(value)
@ -196,10 +160,12 @@ module HTTPX
params form json xml body ssl http2_settings
request_class response_class headers_class request_body_class
response_body_class connection_class options_class
io fallback_protocol debug debug_level transport_options resolver_class resolver_options
io fallback_protocol debug debug_level resolver_class resolver_options
persistent
].each do |method_name|
def_option(method_name)
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
def option_#{method_name}(v); v; end # def option_smth(v); v; end
OUT
end
REQUEST_IVARS = %i[@params @form @xml @json @body].freeze

View File

@ -139,12 +139,6 @@ module HTTPX
super
end
end
def self.const_missing(const_name)
super unless const_name == :StreamResponse
warn "DEPRECATION WARNING: the class #{self}::StreamResponse is deprecated. Use HTTPX::StreamResponse instead."
HTTPX::StreamResponse
end
end
register_plugin :stream, Stream
end

View File

@ -19,10 +19,6 @@ module HTTPX
def_delegator :@body, :empty?
def initialize(verb, uri, options = {})
if verb.is_a?(Symbol)
warn "DEPRECATION WARNING: Using symbols for `verb` is deprecated, and will not be supported in httpx 1.0. " \
"Use \"#{verb.to_s.upcase}\" instead."
end
@verb = verb.to_s.upcase
@options = Options.new(options)
@uri = Utils.to_uri(uri)

View File

@ -358,11 +358,6 @@ module HTTPX
log_exception(@error)
end
def status
warn ":#{__method__} is deprecated, use :error.message instead"
@error.message
end
def to_s
@error.full_message(highlight: false)
end

View File

@ -339,16 +339,6 @@ module HTTPX
end
self
end
# :nocov:
def plugins(pls)
warn ":#{__method__} is deprecated, use :plugin instead"
pls.each do |pl|
plugin(pl)
end
self
end
# :nocov:
end
end

View File

@ -16,8 +16,6 @@ module HTTPX
def self.new: (?options) -> instance
def self.def_option: (Symbol, ?String) -> void
| (Symbol) { (*nil) -> untyped } -> void
# headers
attr_reader uri: URI?
@ -48,9 +46,6 @@ module HTTPX
# transport
attr_reader transport: "unix" | nil
# transport_options
attr_reader transport_options: Hash[untyped, untyped]?
# addresses
attr_reader addresses: Array[ipaddr]?

View File

@ -5,11 +5,6 @@ require_relative "test_helper"
class ErrorResponseTest < Minitest::Test
include HTTPX
def test_error_response_status
r1 = ErrorResponse.new(request_mock, RuntimeError.new("wow"), {})
assert r1.status == "wow"
end
def test_error_response_finished?
r1 = ErrorResponse.new(request_mock, RuntimeError.new("wow"), {})
assert r1.finished?

View File

@ -10,33 +10,6 @@ class OptionsTest < Minitest::Test
assert ex.message == "unknown option: foo", ex.message
end
def test_options_def_option_plain
opts = Class.new(Options) do
def_option(:foo)
end.new(foo: "1")
assert opts.foo == "1", "foo wasn't set"
end
def test_options_def_option_str_eval
opts = Class.new(Options) do
def_option(:foo, <<-OUT)
Integer(value)
OUT
end.new(foo: "1")
assert opts.foo == 1, "foo wasn't set or converted"
end
def test_options_def_option_block
bar = nil
_opts = Class.new(Options) do
def_option(:foo) do |value|
bar = 2
value
end
end.new(foo: "1")
assert bar == 2, "bar hasn't been set"
end unless RUBY_VERSION >= "3.0.0"
def test_options_body
opt1 = Options.new
assert opt1.body.nil?, "body shouldn't be set by default"

View File

@ -19,7 +19,7 @@ module Requests
def test_plugin_follow_redirects_no_location_no_follow
session = HTTPX.plugin(:follow_redirects)
response = session.headers("if-none-match" => "justforcingcachedresponse").get(redirect_no_follow_uri)
response = session.with(headers: { "if-none-match" => "justforcingcachedresponse" }).get(redirect_no_follow_uri)
verify_status(response, 304)
end

View File

@ -15,6 +15,17 @@ module Requests
assert no_stream_response.to_s == stream_response.to_s, "content should be the same"
assert stream_response.respond_to?(:headers) # test respond_to_missing?
no_stream_headers = no_stream_response.headers.to_h
no_stream_headers.delete("date")
stream_headers = no_stream_response.headers.to_h
stream_headers.delete("date")
assert no_stream_headers == stream_headers, "headers should be the same " \
"(h1: #{no_stream_response.headers}, " \
"(h2: #{stream_response.headers}) "
assert session.total_responses.size == 2, "there should be 2 available responses"
end