mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-12-07 00:00:31 -05:00
updated rubocop to 1.0.0 on possible rubies, making the necessary changes
This commit is contained in:
parent
d900225f2e
commit
1b26977d16
@ -1 +1,7 @@
|
|||||||
inherit_from: .rubocop-2.3.yml
|
inherit_from: .rubocop-2.3.yml
|
||||||
|
|
||||||
|
Style/OptionalBooleanParameter:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Gemspec/RequiredRubyVersion:
|
||||||
|
Enabled: false
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
inherit_from: .rubocop-2.3.yml
|
inherit_from: .rubocop-2.4.yml
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
inherit_from: .rubocop-2.3.yml
|
inherit_from: .rubocop-2.4.yml
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
inherit_from: .rubocop-2.3.yml
|
inherit_from: .rubocop-2.4.yml
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
inherit_from: .rubocop-2.3.yml
|
inherit_from: .rubocop-2.4.yml
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
TargetRubyVersion: 2.3
|
TargetRubyVersion: 2.4
|
||||||
DisplayCopNames: true
|
DisplayCopNames: true
|
||||||
Include:
|
Include:
|
||||||
- lib/**/*.rb
|
- lib/**/*.rb
|
||||||
|
|||||||
@ -37,3 +37,8 @@ Style/Documentation:
|
|||||||
Naming/AccessorMethodName:
|
Naming/AccessorMethodName:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Lint/UriEscapeUnescape:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Gemspec/RequiredRubyVersion:
|
||||||
|
Enabled: false
|
||||||
4
Gemfile
4
Gemfile
@ -16,8 +16,10 @@ group :test do
|
|||||||
gem "net-ssh", "~> 4.2.0"
|
gem "net-ssh", "~> 4.2.0"
|
||||||
elsif RUBY_VERSION < "2.3"
|
elsif RUBY_VERSION < "2.3"
|
||||||
gem "rubocop", "~> 0.68.1"
|
gem "rubocop", "~> 0.68.1"
|
||||||
|
elsif RUBY_VERSION < "2.3"
|
||||||
|
gem "rubocop", "~> 0.81.1"
|
||||||
else
|
else
|
||||||
gem "rubocop", "~> 0.80.0"
|
gem "rubocop", "~> 1.0.0"
|
||||||
gem "rubocop-performance", "~> 1.5.2"
|
gem "rubocop-performance", "~> 1.5.2"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -121,7 +121,7 @@ module Faraday
|
|||||||
end
|
end
|
||||||
|
|
||||||
def respond_to_missing?(meth)
|
def respond_to_missing?(meth)
|
||||||
@env.respond_to?(meth)
|
@env.respond_to?(meth) || super
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(meth, *args, &blk)
|
def method_missing(meth, *args, &blk)
|
||||||
|
|||||||
@ -142,7 +142,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def purge_pending
|
def purge_pending(&block)
|
||||||
pendings = []
|
pendings = []
|
||||||
if @parser
|
if @parser
|
||||||
@inflight -= @parser.pending.size
|
@inflight -= @parser.pending.size
|
||||||
@ -150,9 +150,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
pendings << @pending
|
pendings << @pending
|
||||||
pendings.each do |pending|
|
pendings.each do |pending|
|
||||||
pending.reject! do |request|
|
pending.reject!(&block)
|
||||||
yield request
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -460,7 +458,6 @@ module HTTPX
|
|||||||
throw(:jump_tick)
|
throw(:jump_tick)
|
||||||
rescue Errno::ECONNREFUSED,
|
rescue Errno::ECONNREFUSED,
|
||||||
Errno::EADDRNOTAVAIL,
|
Errno::EADDRNOTAVAIL,
|
||||||
Errno::EHOSTUNREACH,
|
|
||||||
OpenSSL::SSL::SSLError => e
|
OpenSSL::SSL::SSLError => e
|
||||||
# connect errors, exit gracefully
|
# connect errors, exit gracefully
|
||||||
handle_error(e)
|
handle_error(e)
|
||||||
|
|||||||
@ -181,7 +181,7 @@ module HTTPX
|
|||||||
def manage_connection(response)
|
def manage_connection(response)
|
||||||
connection = response.headers["connection"]
|
connection = response.headers["connection"]
|
||||||
case connection
|
case connection
|
||||||
when /keep\-alive/i
|
when /keep-alive/i
|
||||||
keep_alive = response.headers["keep-alive"]
|
keep_alive = response.headers["keep-alive"]
|
||||||
return unless keep_alive
|
return unless keep_alive
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ module HTTPX
|
|||||||
|
|
||||||
NativeResolveError = Class.new(ResolveError) do
|
NativeResolveError = Class.new(ResolveError) do
|
||||||
attr_reader :connection, :host
|
attr_reader :connection, :host
|
||||||
|
|
||||||
def initialize(connection, host, message = "Can't resolve #{host}")
|
def initialize(connection, host, message = "Can't resolve #{host}")
|
||||||
@connection = connection
|
@connection = connection
|
||||||
@host = host
|
@host = host
|
||||||
|
|||||||
@ -54,6 +54,18 @@ module HTTPX
|
|||||||
Numeric.__send__(:include, NegMethods)
|
Numeric.__send__(:include, NegMethods)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module RegexpExtensions
|
||||||
|
# If you wonder why this is there: the oauth feature uses a refinement to enhance the
|
||||||
|
# Regexp class locally with #match? , but this is never tested, because ActiveSupport
|
||||||
|
# monkey-patches the same method... Please ActiveSupport, stop being so intrusive!
|
||||||
|
# :nocov:
|
||||||
|
refine(Regexp) do
|
||||||
|
def match?(*args)
|
||||||
|
!match(*args).nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module URIExtensions
|
module URIExtensions
|
||||||
refine URI::Generic do
|
refine URI::Generic do
|
||||||
def non_ascii_hostname
|
def non_ascii_hostname
|
||||||
|
|||||||
@ -7,11 +7,7 @@ module HTTPX
|
|||||||
class TCP
|
class TCP
|
||||||
include Loggable
|
include Loggable
|
||||||
|
|
||||||
attr_reader :ip, :port
|
attr_reader :ip, :port, :addresses, :state
|
||||||
|
|
||||||
attr_reader :addresses
|
|
||||||
|
|
||||||
attr_reader :state
|
|
||||||
|
|
||||||
alias_method :host, :ip
|
alias_method :host, :ip
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ module HTTPX
|
|||||||
|
|
||||||
def_delegator :@uri, :port, :scheme
|
def_delegator :@uri, :port, :scheme
|
||||||
|
|
||||||
|
# rubocop:disable Lint/MissingSuper
|
||||||
def initialize(uri, addresses, options)
|
def initialize(uri, addresses, options)
|
||||||
@uri = uri
|
@uri = uri
|
||||||
@addresses = addresses
|
@addresses = addresses
|
||||||
@ -29,6 +30,7 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
@io ||= build_socket
|
@io ||= build_socket
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Lint/MissingSuper
|
||||||
|
|
||||||
def hostname
|
def hostname
|
||||||
@uri.host
|
@uri.host
|
||||||
|
|||||||
@ -57,7 +57,7 @@ module HTTPX
|
|||||||
idx = @buffer.index("\n")
|
idx = @buffer.index("\n")
|
||||||
return unless idx
|
return unless idx
|
||||||
|
|
||||||
(m = %r{\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?}in.match(@buffer)) ||
|
(m = %r{\AHTTP(?:/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?}in.match(@buffer)) ||
|
||||||
raise(Error, "wrong head line format")
|
raise(Error, "wrong head line format")
|
||||||
version, code, _ = m.captures
|
version, code, _ = m.captures
|
||||||
raise(Error, "unsupported HTTP version (HTTP/#{version})") unless VERSIONS.include?(version)
|
raise(Error, "unsupported HTTP version (HTTP/#{version})") unless VERSIONS.include?(version)
|
||||||
|
|||||||
@ -46,11 +46,8 @@ module HTTPX
|
|||||||
super
|
super
|
||||||
return if @body.nil?
|
return if @body.nil?
|
||||||
|
|
||||||
if (threshold = options.compression_threshold_size)
|
threshold = options.compression_threshold_size
|
||||||
unless unbounded_body?
|
return if threshold && !unbounded_body? && @body.bytesize < threshold
|
||||||
return if @body.bytesize < threshold
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@headers.get("content-encoding").each do |encoding|
|
@headers.get("content-encoding").each do |encoding|
|
||||||
next if encoding == "identity"
|
next if encoding == "identity"
|
||||||
|
|||||||
@ -11,13 +11,7 @@ module HTTPX
|
|||||||
# least)
|
# least)
|
||||||
MAX_LENGTH = 4096
|
MAX_LENGTH = 4096
|
||||||
|
|
||||||
attr_reader :domain
|
attr_reader :domain, :path, :name, :value, :created_at
|
||||||
|
|
||||||
attr_reader :path
|
|
||||||
|
|
||||||
attr_reader :name, :value
|
|
||||||
|
|
||||||
attr_reader :created_at
|
|
||||||
|
|
||||||
def path=(path)
|
def path=(path)
|
||||||
path = String(path)
|
path = String(path)
|
||||||
|
|||||||
@ -3,23 +3,10 @@
|
|||||||
require "strscan"
|
require "strscan"
|
||||||
require "time"
|
require "time"
|
||||||
|
|
||||||
module HTTPX::Plugins::Cookies
|
module HTTPX
|
||||||
|
module Plugins::Cookies
|
||||||
module SetCookieParser
|
module SetCookieParser
|
||||||
unless Regexp.method_defined?(:match?)
|
using(RegexpExtensions) unless Regexp.method_defined?(:match?)
|
||||||
# If you wonder why this is there: the oauth feature uses a refinement to enhance the
|
|
||||||
# Regexp class locally with #match? , but this is never tested, because ActiveSupport
|
|
||||||
# monkey-patches the same method... Please ActiveSupport, stop being so intrusive!
|
|
||||||
# :nocov:
|
|
||||||
module RegexpExtensions
|
|
||||||
refine(Regexp) do
|
|
||||||
def match?(*args)
|
|
||||||
!match(*args).nil?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
using(RegexpExtensions)
|
|
||||||
# :nocov:
|
|
||||||
end
|
|
||||||
|
|
||||||
# Whitespace.
|
# Whitespace.
|
||||||
RE_WSP = /[ \t]+/.freeze
|
RE_WSP = /[ \t]+/.freeze
|
||||||
@ -78,7 +65,7 @@ module HTTPX::Plugins::Cookies
|
|||||||
name = scanner.scan(RE_NAME)
|
name = scanner.scan(RE_NAME)
|
||||||
name.rstrip! if name
|
name.rstrip! if name
|
||||||
|
|
||||||
if scanner.skip(/\=/)
|
if scanner.skip(/=/)
|
||||||
value = scan_value(scanner, comma_as_separator)
|
value = scan_value(scanner, comma_as_separator)
|
||||||
else
|
else
|
||||||
scan_value(scanner, comma_as_separator)
|
scan_value(scanner, comma_as_separator)
|
||||||
@ -152,3 +139,4 @@ module HTTPX::Plugins::Cookies
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -81,7 +81,7 @@ module HTTPX
|
|||||||
|
|
||||||
uri = request.path
|
uri = request.path
|
||||||
|
|
||||||
params = Hash[auth_info.split(/ *, */)
|
params = Hash[auth_info.split(/ *, */) # rubocop:disable Style/HashTransformValues
|
||||||
.map { |val| val.split("=") }
|
.map { |val| val.split("=") }
|
||||||
.map { |k, v| [k, v.delete("\"")] }]
|
.map { |k, v| [k, v.delete("\"")] }]
|
||||||
nonce = params["nonce"]
|
nonce = params["nonce"]
|
||||||
|
|||||||
@ -33,11 +33,8 @@ module HTTPX
|
|||||||
super
|
super
|
||||||
return if @body.nil?
|
return if @body.nil?
|
||||||
|
|
||||||
if (threshold = options.expect_threshold_size)
|
threshold = options.expect_threshold_size
|
||||||
unless unbounded_body?
|
return if threshold && !unbounded_body? && @body.bytesize < threshold
|
||||||
return if @body.bytesize < threshold
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@headers["expect"] = "100-continue"
|
@headers["expect"] = "100-continue"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -91,6 +91,8 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Packet
|
module Packet
|
||||||
|
using(RegexpExtensions) unless Regexp.method_defined?(:match?)
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def connect(parameters, uri)
|
def connect(parameters, uri)
|
||||||
@ -101,7 +103,7 @@ module HTTPX
|
|||||||
|
|
||||||
packet << [ip.to_i].pack("N")
|
packet << [ip.to_i].pack("N")
|
||||||
rescue IPAddr::InvalidAddressError
|
rescue IPAddr::InvalidAddressError
|
||||||
if parameters.uri.scheme =~ /^socks4a?$/
|
if /^socks4a?$/.match?(parameters.uri.scheme)
|
||||||
# resolv defaults to IPv4, and socks4 doesn't support IPv6 otherwise
|
# resolv defaults to IPv4, and socks4 doesn't support IPv6 otherwise
|
||||||
ip = IPAddr.new(Resolv.getaddress(uri.host))
|
ip = IPAddr.new(Resolv.getaddress(uri.host))
|
||||||
packet << [ip.to_i].pack("N")
|
packet << [ip.to_i].pack("N")
|
||||||
|
|||||||
@ -166,7 +166,6 @@ module HTTPX
|
|||||||
resolver.on(:error, &method(:on_resolver_error))
|
resolver.on(:error, &method(:on_resolver_error))
|
||||||
resolver.on(:close) { on_resolver_close(resolver) }
|
resolver.on(:close) { on_resolver_close(resolver) }
|
||||||
resolver
|
resolver
|
||||||
# rubocop: disable Layout/RescueEnsureAlignment
|
|
||||||
rescue ArgumentError
|
rescue ArgumentError
|
||||||
# this block is here because of an error which happens on CI from time to time
|
# this block is here because of an error which happens on CI from time to time
|
||||||
warn "tried resolver: #{resolver_type}"
|
warn "tried resolver: #{resolver_type}"
|
||||||
@ -174,7 +173,6 @@ module HTTPX
|
|||||||
warn "new: #{resolver_type.method(:new).source_location}"
|
warn "new: #{resolver_type.method(:new).source_location}"
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
# rubocop: enable Layout/RescueEnsureAlignment
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,9 +33,7 @@ module HTTPX
|
|||||||
|
|
||||||
USER_AGENT = "httpx.rb/#{VERSION}"
|
USER_AGENT = "httpx.rb/#{VERSION}"
|
||||||
|
|
||||||
attr_reader :verb, :uri, :headers, :body, :state
|
attr_reader :verb, :uri, :headers, :body, :state, :options, :response
|
||||||
|
|
||||||
attr_reader :options, :response
|
|
||||||
|
|
||||||
def_delegator :@body, :empty?
|
def_delegator :@body, :empty?
|
||||||
|
|
||||||
|
|||||||
@ -213,7 +213,7 @@ module HTTPX
|
|||||||
case response.headers["content-type"]
|
case response.headers["content-type"]
|
||||||
when "application/dns-json",
|
when "application/dns-json",
|
||||||
"application/json",
|
"application/json",
|
||||||
%r{^application\/x\-javascript} # because google...
|
%r{^application/x-javascript} # because google...
|
||||||
payload = JSON.parse(response.to_s)
|
payload = JSON.parse(response.to_s)
|
||||||
payload["Answer"]
|
payload["Answer"]
|
||||||
when "application/dns-udpwireformat",
|
when "application/dns-udpwireformat",
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class HTTPX::Selector
|
|||||||
READ_INTERESTS = %i[r rw].freeze
|
READ_INTERESTS = %i[r rw].freeze
|
||||||
WRITE_INTERESTS = %i[w rw].freeze
|
WRITE_INTERESTS = %i[w rw].freeze
|
||||||
|
|
||||||
def select_many(interval)
|
def select_many(interval, &block)
|
||||||
selectables, r, w = nil
|
selectables, r, w = nil
|
||||||
|
|
||||||
# first, we group IOs based on interest type. On call to #interests however,
|
# first, we group IOs based on interest type. On call to #interests however,
|
||||||
@ -102,9 +102,7 @@ class HTTPX::Selector
|
|||||||
writers.delete(io)
|
writers.delete(io)
|
||||||
end if readers
|
end if readers
|
||||||
|
|
||||||
writers.each do |io|
|
writers.each(&block) if writers
|
||||||
yield io
|
|
||||||
end if writers
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_one(interval)
|
def select_one(interval)
|
||||||
|
|||||||
@ -190,7 +190,6 @@ module HTTPX
|
|||||||
begin
|
begin
|
||||||
# guarantee ordered responses
|
# guarantee ordered responses
|
||||||
loop do
|
loop do
|
||||||
begin
|
|
||||||
request = requests.first
|
request = requests.first
|
||||||
pool.next_tick until (response = fetch_response(request, connections, request_options))
|
pool.next_tick until (response = fetch_response(request, connections, request_options))
|
||||||
|
|
||||||
@ -199,7 +198,6 @@ module HTTPX
|
|||||||
|
|
||||||
break if requests.empty? || pool.empty?
|
break if requests.empty? || pool.empty?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
responses
|
responses
|
||||||
ensure
|
ensure
|
||||||
close(connections) unless @persistent
|
close(connections) unless @persistent
|
||||||
|
|||||||
@ -91,10 +91,8 @@ module ProfilerHelpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def memory_profile
|
def memory_profile(&block)
|
||||||
require "memory_profiler"
|
require "memory_profiler"
|
||||||
MemoryProfiler.report(allow_files: ["lib/httpx"]) do
|
MemoryProfiler.report(allow_files: ["lib/httpx"], &block).pretty_print
|
||||||
yield
|
|
||||||
end.pretty_print
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -40,8 +40,8 @@ class HTTPTest < Minitest::Test
|
|||||||
assert log_output.match(/HEADER: Connection: close/)
|
assert log_output.match(/HEADER: Connection: close/)
|
||||||
# assert response headers
|
# assert response headers
|
||||||
assert log_output.match(%r{HEADLINE: 200 HTTP/1\.1})
|
assert log_output.match(%r{HEADLINE: 200 HTTP/1\.1})
|
||||||
assert log_output.match(/HEADER: content\-type: \w+/)
|
assert log_output.match(/HEADER: content-type: \w+/)
|
||||||
assert log_output.match(/HEADER: content\-length: \d+/)
|
assert log_output.match(/HEADER: content-length: \d+/)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -70,8 +70,8 @@ class HTTPSTest < Minitest::Test
|
|||||||
assert log_output.match(%r{HEADER: accept: */*})
|
assert log_output.match(%r{HEADER: accept: */*})
|
||||||
# assert response headers
|
# assert response headers
|
||||||
assert log_output.match(/HEADER: :status: 200/)
|
assert log_output.match(/HEADER: :status: 200/)
|
||||||
assert log_output.match(/HEADER: content\-type: \w+/)
|
assert log_output.match(/HEADER: content-type: \w+/)
|
||||||
assert log_output.match(/HEADER: content\-length: \d+/)
|
assert log_output.match(/HEADER: content-length: \d+/)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -192,7 +192,7 @@ module Requests
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cookies_set_uri(cookies)
|
def cookies_set_uri(cookies)
|
||||||
build_uri("/cookies/set?" + URI.encode_www_form(cookies))
|
build_uri("/cookies/set?#{URI.encode_www_form(cookies)}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_cookies(jar, cookies)
|
def verify_cookies(jar, cookies)
|
||||||
|
|||||||
@ -67,7 +67,7 @@ module Requests
|
|||||||
private
|
private
|
||||||
|
|
||||||
def redirect_uri(redirect_uri = redirect_location)
|
def redirect_uri(redirect_uri = redirect_location)
|
||||||
build_uri("/redirect-to?url=" + redirect_uri)
|
build_uri("/redirect-to?url=#{redirect_uri}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_redirect_uri(n)
|
def max_redirect_uri(n)
|
||||||
|
|||||||
@ -88,8 +88,8 @@ module Requests
|
|||||||
define_method :"test_#{meth}_multiple_params" do
|
define_method :"test_#{meth}_multiple_params" do
|
||||||
uri = build_uri("/#{meth}")
|
uri = build_uri("/#{meth}")
|
||||||
response1, response2 = HTTPX.request([
|
response1, response2 = HTTPX.request([
|
||||||
[meth, uri, body: "data"],
|
[meth, uri, { body: "data" }],
|
||||||
[meth, uri, form: { "foo" => "bar" }],
|
[meth, uri, { form: { "foo" => "bar" } }],
|
||||||
], max_concurrent_requests: 1) # because httpbin sucks and can't handle pipeline requests
|
], max_concurrent_requests: 1) # because httpbin sucks and can't handle pipeline requests
|
||||||
|
|
||||||
verify_status(response1, 200)
|
verify_status(response1, 200)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user