mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
initializing error classes more conventionally
This commit is contained in:
parent
6275108b49
commit
08fa918537
@ -32,7 +32,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def shift!(fin)
|
||||
@buffer = @buffer.byteslice(fin..-1)
|
||||
@buffer = @buffer.byteslice(fin..-1) || "".b
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def emit(type, *args)
|
||||
callbacks(type).delete_if { |pr| :delete == pr[*args] } # rubocop:disable Style/YodaCondition
|
||||
callbacks(type).delete_if { |pr| :delete == pr.call(*args) } # rubocop:disable Style/YodaCondition
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -34,11 +34,11 @@ module HTTPX
|
||||
branch(default_options).wrap(&blk)
|
||||
end
|
||||
|
||||
def plugin(*args, **opts, &blk)
|
||||
def plugin(pl, options = nil, &blk)
|
||||
klass = is_a?(Session) ? self.class : Session
|
||||
klass = Class.new(klass)
|
||||
klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
|
||||
klass.plugin(*args, **opts, &blk).new
|
||||
klass.plugin(pl, options, &blk).new
|
||||
end
|
||||
|
||||
# deprecated
|
||||
|
@ -69,10 +69,10 @@ module HTTPX
|
||||
end
|
||||
|
||||
@inflight = 0
|
||||
@keep_alive_timeout = options.timeout[:keep_alive_timeout]
|
||||
@keep_alive_timeout = @options.timeout[:keep_alive_timeout]
|
||||
@keep_alive_timer = nil
|
||||
|
||||
self.addresses = options.addresses if options.addresses
|
||||
self.addresses = @options.addresses if @options.addresses
|
||||
end
|
||||
|
||||
# this is a semi-private method, to be used by the resolver
|
||||
|
@ -11,7 +11,7 @@ module HTTPX
|
||||
|
||||
MAX_CONCURRENT_REQUESTS = HTTP2Next::DEFAULT_MAX_CONCURRENT_STREAMS
|
||||
|
||||
Error = Class.new(Error) do
|
||||
class Error < Error
|
||||
def initialize(id, code)
|
||||
super("stream #{id} closed with error: #{code}")
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module HTTPX
|
||||
Error = Class.new(StandardError)
|
||||
class Error < StandardError; end
|
||||
|
||||
UnsupportedSchemeError = Class.new(Error)
|
||||
class UnsupportedSchemeError < Error; end
|
||||
|
||||
TimeoutError = Class.new(Error) do
|
||||
class TimeoutError < Error
|
||||
attr_reader :timeout
|
||||
|
||||
def initialize(timeout, message)
|
||||
@ -20,17 +20,17 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
TotalTimeoutError = Class.new(TimeoutError)
|
||||
class TotalTimeoutError < TimeoutError; end
|
||||
|
||||
ConnectTimeoutError = Class.new(TimeoutError)
|
||||
class ConnectTimeoutError < TimeoutError; end
|
||||
|
||||
SettingsTimeoutError = Class.new(TimeoutError)
|
||||
class SettingsTimeoutError < TimeoutError; end
|
||||
|
||||
ResolveTimeoutError = Class.new(TimeoutError)
|
||||
class ResolveTimeoutError < TimeoutError; end
|
||||
|
||||
ResolveError = Class.new(Error)
|
||||
class ResolveError < Error; end
|
||||
|
||||
NativeResolveError = Class.new(ResolveError) do
|
||||
class NativeResolveError < ResolveError
|
||||
attr_reader :connection, :host
|
||||
|
||||
def initialize(connection, host, message = "Can't resolve #{host}")
|
||||
@ -40,7 +40,7 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
HTTPError = Class.new(Error) do
|
||||
class HTTPError < Error
|
||||
attr_reader :response
|
||||
|
||||
def initialize(response)
|
||||
@ -53,5 +53,5 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
MisdirectedRequestError = Class.new(HTTPError)
|
||||
class MisdirectedRequestError < HTTPError; end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ require "openssl"
|
||||
|
||||
module HTTPX
|
||||
class TLS < TCP
|
||||
Error = Class.new(StandardError)
|
||||
class Error < StandardError; end
|
||||
|
||||
def initialize(_, _, options)
|
||||
super
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
module HTTPX
|
||||
module Parser
|
||||
Error = Class.new(Error)
|
||||
class Error < Error; end
|
||||
|
||||
class HTTP1
|
||||
VERSIONS = %w[1.0 1.1].freeze
|
||||
|
@ -4,7 +4,8 @@ require "resolv"
|
||||
require "ipaddr"
|
||||
|
||||
module HTTPX
|
||||
Socks4Error = Class.new(Error)
|
||||
class Socks4Error < Error; end
|
||||
|
||||
module Plugins
|
||||
module Proxy
|
||||
module Socks4
|
||||
|
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module HTTPX
|
||||
Socks5Error = Class.new(Error)
|
||||
class Socks5Error < Error; end
|
||||
|
||||
module Plugins
|
||||
module Proxy
|
||||
module Socks5
|
||||
|
@ -31,7 +31,7 @@ module HTTPX
|
||||
#
|
||||
module Registry
|
||||
# Base Registry Error
|
||||
Error = Class.new(Error)
|
||||
class Error < Error; end
|
||||
|
||||
def self.extended(klass)
|
||||
super
|
||||
|
@ -204,7 +204,7 @@ module HTTPX
|
||||
@buffer = Tempfile.new("httpx", encoding: Encoding::BINARY, mode: File::RDWR)
|
||||
else
|
||||
@state = :memory
|
||||
@buffer = StringIO.new("".b, File::RDWR)
|
||||
@buffer = StringIO.new("".b)
|
||||
end
|
||||
when :memory
|
||||
if @length > @threshold_size
|
||||
|
@ -43,9 +43,6 @@ class HTTPX::Selector
|
||||
|
||||
private
|
||||
|
||||
READ_INTERESTS = %i[r rw].freeze
|
||||
WRITE_INTERESTS = %i[w rw].freeze
|
||||
|
||||
def select_many(interval, &block)
|
||||
selectables, r, w = nil
|
||||
|
||||
@ -64,8 +61,8 @@ class HTTPX::Selector
|
||||
selectables.each do |io|
|
||||
interests = io.interests
|
||||
|
||||
(r ||= []) << io if READ_INTERESTS.include?(interests)
|
||||
(w ||= []) << io if WRITE_INTERESTS.include?(interests)
|
||||
(r ||= []) << io if READABLE.include?(interests)
|
||||
(w ||= []) << io if WRITABLE.include?(interests)
|
||||
end
|
||||
|
||||
if @selectables.empty?
|
||||
|
@ -15,8 +15,6 @@ module HTTPX
|
||||
end
|
||||
|
||||
def wrap
|
||||
return unless block_given?
|
||||
|
||||
begin
|
||||
prev_persistent = @persistent
|
||||
@persistent = true
|
||||
@ -31,6 +29,8 @@ module HTTPX
|
||||
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
|
||||
@ -283,8 +283,8 @@ module HTTPX
|
||||
# :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
|
||||
|
@ -4,7 +4,7 @@ require "forwardable"
|
||||
|
||||
module HTTPX::Transcoder
|
||||
module Body
|
||||
Error = Class.new(HTTPX::Error)
|
||||
class Error < HTTPX::Error; end
|
||||
|
||||
module_function
|
||||
|
||||
|
@ -4,7 +4,8 @@ require "forwardable"
|
||||
|
||||
module HTTPX::Transcoder
|
||||
module Chunker
|
||||
Error = Class.new(HTTPX::Error)
|
||||
class Error < HTTPX::Error; end
|
||||
|
||||
CRLF = "\r\n".b
|
||||
|
||||
class Encoder
|
||||
|
Loading…
x
Reference in New Issue
Block a user