diff --git a/lib/httpx/connection.rb b/lib/httpx/connection.rb index 39314db7..687f9d69 100644 --- a/lib/httpx/connection.rb +++ b/lib/httpx/connection.rb @@ -316,7 +316,7 @@ module HTTPX # * the number of inflight requests # * the number of pending requests # * whether the write buffer has bytes (i.e. for close handshake) - if @pending.size.zero? && @inflight.zero? && @write_buffer.empty? + if @pending.empty? && @inflight.zero? && @write_buffer.empty? log(level: 3) { "NO MORE REQUESTS..." } return end @@ -360,7 +360,7 @@ module HTTPX break if @state == :closing || @state == :closed # exit #consume altogether if all outstanding requests have been dealt with - return if @pending.size.zero? && @inflight.zero? + return if @pending.empty? && @inflight.zero? end unless ((ints = interests).nil? || ints == :w || @state == :closing) && !epiped # diff --git a/lib/httpx/connection/http2.rb b/lib/httpx/connection/http2.rb index 185797e0..f812a5cc 100644 --- a/lib/httpx/connection/http2.rb +++ b/lib/httpx/connection/http2.rb @@ -365,7 +365,7 @@ module HTTPX ex.set_backtrace(caller) handle_error(ex) end - return unless is_connection_closed && @streams.size.zero? + return unless is_connection_closed && @streams.empty? emit(:close, is_connection_closed) end diff --git a/lib/httpx/options.rb b/lib/httpx/options.rb index 2bd97094..25b98fda 100644 --- a/lib/httpx/options.rb +++ b/lib/httpx/options.rb @@ -100,7 +100,7 @@ module HTTPX end def def_option(optname, *args, &block) - if args.size.zero? && !block + if args.empty? && !block class_eval(<<-OUT, __FILE__, __LINE__ + 1) def option_#{optname}(v); v; end # def option_smth(v); v; end OUT diff --git a/lib/httpx/plugins/compression.rb b/lib/httpx/plugins/compression.rb index aebf9f82..4e27655b 100644 --- a/lib/httpx/plugins/compression.rb +++ b/lib/httpx/plugins/compression.rb @@ -138,7 +138,7 @@ module HTTPX def each(&blk) return enum_for(__method__) unless blk - return deflate(&blk) if @buffer.size.zero? + return deflate(&blk) if @buffer.empty? @buffer.rewind @buffer.each(&blk) @@ -152,7 +152,7 @@ module HTTPX private def deflate(&blk) - return unless @buffer.size.zero? + return unless @buffer.empty? @body.rewind @deflater.deflate(@body, @buffer, chunk_size: 16_384, &blk) diff --git a/lib/httpx/plugins/compression/gzip.rb b/lib/httpx/plugins/compression/gzip.rb index 56e06a37..e8913f7d 100644 --- a/lib/httpx/plugins/compression/gzip.rb +++ b/lib/httpx/plugins/compression/gzip.rb @@ -56,7 +56,7 @@ module HTTPX class Inflater def initialize(bytesize) - @inflater = Zlib::Inflate.new(32 + Zlib::MAX_WBITS) + @inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 32) @bytesize = bytesize @buffer = nil end diff --git a/lib/httpx/plugins/grpc/message.rb b/lib/httpx/plugins/grpc/message.rb index 83e095da..8ed96e8b 100644 --- a/lib/httpx/plugins/grpc/message.rb +++ b/lib/httpx/plugins/grpc/message.rb @@ -57,7 +57,7 @@ module HTTPX yield data - message = message.byteslice((5 + size)..-1) + message = message.byteslice((size + 5)..-1) end end diff --git a/lib/httpx/plugins/retries.rb b/lib/httpx/plugins/retries.rb index c01d306e..f413af23 100644 --- a/lib/httpx/plugins/retries.rb +++ b/lib/httpx/plugins/retries.rb @@ -26,7 +26,7 @@ module HTTPX ConnectionError, Connection::HTTP2::GoawayError, ].freeze - DEFAULT_JITTER = ->(interval) { interval * (0.5 * (1 + rand)) } + DEFAULT_JITTER = ->(interval) { interval * ((rand + 1) * 0.5) } if ENV.key?("HTTPX_NO_JITTER") def self.extra_options(options)