Compare commits

..

No commits in common. "b1fc1907ab27fa40c01f55b9d0a5849040a42e25" and "5feba82ffbec1e2a1c3bafa348addb8a9a573e2d" have entirely different histories.

10 changed files with 11 additions and 36 deletions

View File

@ -55,9 +55,9 @@ group :test do
end
group :lint do
gem "rubocop", "~> 1.59.0"
gem "rubocop"
gem "rubocop-md"
gem "rubocop-performance", "~> 1.19.0"
gem "rubocop-performance"
end
group :coverage do

View File

@ -3,14 +3,6 @@
require "forwardable"
module HTTPX
# Internal class to abstract a string buffer, by wrapping a string and providing the
# minimum possible API and functionality required.
#
# buffer = Buffer.new(640)
# buffer.full? #=> false
# buffer << "aa"
# buffer.capacity #=> 638
#
class Buffer
extend Forwardable

View File

@ -1,8 +1,6 @@
# frozen_string_literal: true
module HTTPX
# Session mixin, implements most of the APIs that the users call.
# delegates to a default session when extended.
module Chainable
%w[head get post put delete trace options connect patch].each do |meth|
class_eval(<<-MOD, __FILE__, __LINE__ + 1)
@ -12,7 +10,6 @@ module HTTPX
MOD
end
# delegates to the default session (see HTTPX::Session#request).
def request(*args, **options)
branch(default_options).request(*args, **options)
end
@ -21,12 +18,10 @@ module HTTPX
with(headers: { "accept" => String(type) })
end
# delegates to the default session (see HTTPX::Session#wrap).
def wrap(&blk)
branch(default_options).wrap(&blk)
end
# returns a new instance loaded with the +pl+ plugin and +options+.
def plugin(pl, options = nil, &blk)
klass = is_a?(S) ? self.class : Session
klass = Class.new(klass)
@ -34,19 +29,16 @@ module HTTPX
klass.plugin(pl, options, &blk).new
end
# returns a new instance loaded with +options+.
def with(options, &blk)
branch(default_options.merge(options), &blk)
end
private
# returns default instance of HTTPX::Options.
def default_options
@options || Session.default_options
end
# returns a default instance of HTTPX::Session.
def branch(options, &blk)
return self.class.new(options, &blk) if is_a?(S)

View File

@ -700,7 +700,7 @@ module HTTPX
interval = @timers.after(timeout, callback)
Array(finish_events).each do |event|
# clean up request timeouts if the connection errors out
# clean up reques timeouts if the connection errors out
request.once(event) do
if @intervals.include?(interval)
interval.delete(callback)

View File

@ -99,7 +99,7 @@ module HTTPX
# :compress_request_body :: whether to auto-decompress response body (defaults to <tt>true</tt>)
# :timeout :: hash of timeout configurations (supports <tt>:connect_timeout</tt>, <tt>:settings_timeout</tt>,
# <tt>:operation_timeout</tt>, <tt>:keep_alive_timeout</tt>, <tt>:read_timeout</tt>, <tt>:write_timeout</tt>
# and <tt>:request_timeout</tt>
# and <tt>:request_timeout</tt>
# :headers :: hash of HTTP headers (ex: <tt>{ "x-custom-foo" => "bar" }</tt>)
# :window_size :: number of bytes to read from a socket
# :buffer_size :: internal read and write buffer size in bytes

View File

@ -138,14 +138,9 @@ module HTTPX
# Indicates no such domain was found.
host = @requests.delete(request)
connection = reset_hostname(host, reset_candidates: false)
connection = reset_hostname(host)
unless @queries.value?(connection)
emit_resolve_error(connection)
return
end
resolve
emit_resolve_error(connection)
when :dns_error
host = @requests.delete(request)
connection = reset_hostname(host)

View File

@ -70,10 +70,9 @@ module HTTPX
@body.write(data)
end
# returns the HTTPX::ContentType for the response, as per what's declared in the content-type header.
# returns the response mime type, as per what's declared in the content-type header.
#
# response.content_type #=> #<HTTPX::ContentType:xxx @header_value="text/plain">
# response.content_type.mime_type #=> "text/plain"
# response.content_type #=> "text/plain"
def content_type
@content_type ||= ContentType.new(@headers["content-type"])
end

View File

@ -166,7 +166,6 @@ module HTTPX
private
# prepares inflaters for the advertised encodings in "content-encoding" header.
def initialize_inflaters
@inflaters = nil
@ -188,7 +187,6 @@ module HTTPX
end
end
# passes the +chunk+ through all inflaters to decode it.
def decode_chunk(chunk)
@inflaters.reverse_each do |inflater|
chunk = inflater.call(chunk)
@ -197,7 +195,6 @@ module HTTPX
chunk
end
# tries transitioning the body STM to the +nextstate+.
def transition(nextstate)
case nextstate
when :open

View File

@ -39,7 +39,7 @@ class HTTP1ParserTest < Minitest::Test
JSON.parse(File.read(File.expand_path("support/responses.json", __dir__))).each do |res_json|
res_json["headers"] ||= {}
define_method :"test_parse_response_#{res_json["name"]}" do
define_method "test_parse_response_#{res_json["name"]}" do
observer = RequestObserver.new
parser = observer.parser
begin

View File

@ -45,7 +45,7 @@ module Requests
end
%w[SHA1 SHA2 SHA256 SHA384 SHA512 RMD160].each do |alg|
define_method :"test_plugin_digest_auth_#{alg}" do
define_method "test_plugin_digest_auth_#{alg}" do
session = HTTPX.plugin(:digest_auth).with_headers("cookie" => "fake=fake_value")
response = session.digest_auth(user, pass).get("#{digest_auth_uri}/#{alg}")
verify_status(response, 200)
@ -56,7 +56,7 @@ module Requests
end
%w[MD5 SHA1].each do |alg|
define_method :"test_plugin_digest_auth_#{alg}_sess" do
define_method "test_plugin_digest_auth_#{alg}_sess" do
start_test_servlet(DigestServer, algorithm: "#{alg}-sess") do |server|
uri = "#{server.origin}/"
session = HTTPX.plugin(:digest_auth).with_headers("cookie" => "fake=fake_value")