mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-05 00:02:38 -04:00
Merge branch 'new-cops-enable' into 'master'
New cops enable See merge request honeyryderchuck/httpx!164
This commit is contained in:
commit
ddabe52946
12
.rubocop.yml
12
.rubocop.yml
@ -3,6 +3,7 @@ inherit_from: .rubocop_todo.yml
|
||||
require: rubocop-performance
|
||||
|
||||
AllCops:
|
||||
NewCops: enable
|
||||
TargetRubyVersion: 2.7
|
||||
DisplayCopNames: true
|
||||
Include:
|
||||
@ -90,12 +91,18 @@ Style/GlobalVars:
|
||||
Style/RedundantBegin:
|
||||
Enabled: false
|
||||
|
||||
Style/HashConversion:
|
||||
Enabled: False
|
||||
|
||||
Performance/TimesMap:
|
||||
Enabled: false
|
||||
|
||||
Performance/RedundantBlockCall:
|
||||
Enabled: false
|
||||
|
||||
Performance/CollectionLiteralInLoop:
|
||||
Enabled: false # most useless perf cop ever...
|
||||
|
||||
Naming/ClassAndModuleCamelCase:
|
||||
Exclude:
|
||||
- regression_tests/**/*.rb
|
||||
@ -134,6 +141,11 @@ Lint/MissingSuper:
|
||||
Exclude:
|
||||
- 'lib/httpx/io/unix.rb'
|
||||
|
||||
Lint/DuplicateBranch:
|
||||
Enabled: false # this doesn't work correctly
|
||||
|
||||
Lint/EmptyBlock:
|
||||
Enabled: false # and neither does this. I don't control 3rd party methods.
|
||||
Style/HashTransformValues:
|
||||
Exclude:
|
||||
- 'lib/httpx/plugins/digest_authentication.rb'
|
||||
|
@ -36,3 +36,6 @@ Style/Documentation:
|
||||
|
||||
Naming/AccessorMethodName:
|
||||
Enabled: false
|
||||
|
||||
Performance/MethodObjectAsBlock:
|
||||
Enabled: false
|
7
Rakefile
7
Rakefile
@ -24,15 +24,12 @@ Rake::TestTask.new(:regressions) do |t|
|
||||
t.warning = false
|
||||
end
|
||||
|
||||
RUBY_MAJOR_MINOR = RUBY_VERSION.split(/\./).first(2).join(".")
|
||||
RUBY_MAJOR_MINOR = RUBY_VERSION.split(".").first(2).join(".")
|
||||
|
||||
begin
|
||||
require "rubocop/rake_task"
|
||||
desc "Run rubocop"
|
||||
RuboCop::RakeTask.new(:rubocop) do |task|
|
||||
# rubocop 0.81 seems to have a race condition somewhere when loading the configs
|
||||
task.options += %w[--parallel]
|
||||
end
|
||||
RuboCop::RakeTask.new
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
|
@ -58,8 +58,8 @@ class WebmockTest < Minitest::Test
|
||||
|
||||
def test_verification_that_expected_request_didnt_occur
|
||||
expected_message = "The request GET #{MOCK_URL_HTTP}/ was expected to execute 1 time but it executed 0 times" \
|
||||
"\n\nThe following requests were made:\n\nNo requests were made.\n" \
|
||||
"============================================================"
|
||||
"\n\nThe following requests were made:\n\nNo requests were made.\n" \
|
||||
"============================================================"
|
||||
assert_raise_with_message(MiniTest::Assertion, expected_message) do
|
||||
assert_requested(:get, MOCK_URL_HTTP)
|
||||
end
|
||||
@ -67,8 +67,8 @@ class WebmockTest < Minitest::Test
|
||||
|
||||
def test_verification_that_expected_stub_didnt_occur
|
||||
expected_message = "The request ANY #{MOCK_URL_HTTP}/ was expected to execute 1 time but it executed 0 times" \
|
||||
"\n\nThe following requests were made:\n\nNo requests were made.\n" \
|
||||
"============================================================"
|
||||
"\n\nThe following requests were made:\n\nNo requests were made.\n" \
|
||||
"============================================================"
|
||||
assert_raise_with_message(MiniTest::Assertion, expected_message) do
|
||||
assert_requested(@stub_http)
|
||||
end
|
||||
|
@ -22,6 +22,8 @@ module Faraday
|
||||
# :nocov:
|
||||
|
||||
module RequestMixin
|
||||
using ::HTTPX::HashExtensions
|
||||
|
||||
private
|
||||
|
||||
def build_request(env)
|
||||
@ -38,7 +40,7 @@ module Faraday
|
||||
timeout_options = {
|
||||
connect_timeout: env.request.open_timeout,
|
||||
operation_timeout: env.request.timeout,
|
||||
}.reject { |_, v| v.nil? }
|
||||
}.compact
|
||||
|
||||
options = {
|
||||
ssl: {},
|
||||
@ -101,7 +103,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def on_response(&blk)
|
||||
if block_given?
|
||||
if blk
|
||||
@on_response = lambda do |response|
|
||||
blk.call(response)
|
||||
end
|
||||
@ -112,7 +114,7 @@ module Faraday
|
||||
end
|
||||
|
||||
def on_complete(&blk)
|
||||
if block_given?
|
||||
if blk
|
||||
@on_complete = blk
|
||||
self
|
||||
else
|
||||
|
@ -4,9 +4,9 @@ module HTTPX
|
||||
module Chainable
|
||||
%i[head get post put delete trace options connect patch].each do |meth|
|
||||
class_eval(<<-MOD, __FILE__, __LINE__ + 1)
|
||||
def #{meth}(*uri, **options)
|
||||
request(:#{meth}, uri, **options)
|
||||
end
|
||||
def #{meth}(*uri, **options) # def get(*uri, **options)
|
||||
request(:#{meth}, uri, **options) # request(:get, uri, **options)
|
||||
end # end
|
||||
MOD
|
||||
end
|
||||
|
||||
|
@ -283,10 +283,10 @@ module HTTPX
|
||||
# on the last request of the possible batch (either allowed max requests,
|
||||
# or if smaller, the size of the batch itself)
|
||||
requests_limit = [@max_requests, @requests.size].min
|
||||
if request != @requests[requests_limit - 1]
|
||||
"keep-alive"
|
||||
else
|
||||
if request == @requests[requests_limit - 1]
|
||||
"close"
|
||||
else
|
||||
"keep-alive"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -388,10 +388,10 @@ module HTTPX
|
||||
end
|
||||
|
||||
def on_pong(ping)
|
||||
if !@pings.delete(ping.to_s)
|
||||
close(:protocol_error, "ping payload did not match")
|
||||
else
|
||||
if @pings.delete(ping.to_s)
|
||||
emit(:pong)
|
||||
else
|
||||
close(:protocol_error, "ping payload did not match")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -123,7 +123,7 @@ module HTTPX
|
||||
|
||||
# RFC 6265 #4.1.1
|
||||
# Domain-value must be a subdomain.
|
||||
@domain && self <= domain && domain <= @domain ? true : false
|
||||
@domain && self <= domain && domain <= @domain
|
||||
end
|
||||
|
||||
# def ==(other)
|
||||
|
@ -54,6 +54,51 @@ module HTTPX
|
||||
Numeric.__send__(:include, NegMethods)
|
||||
end
|
||||
|
||||
module HashExtensions
|
||||
refine Hash do
|
||||
def compact
|
||||
h = {}
|
||||
each do |key, value|
|
||||
h[key] = value unless value == nil
|
||||
end
|
||||
h
|
||||
end unless Hash.method_defined?(:compact)
|
||||
end
|
||||
end
|
||||
|
||||
module ArrayExtensions
|
||||
refine Array do
|
||||
|
||||
def filter_map
|
||||
return to_enum(:filter_map) unless block_given?
|
||||
|
||||
each_with_object([]) do |item, res|
|
||||
processed = yield(item)
|
||||
res << processed if processed
|
||||
end
|
||||
end unless Array.method_defined?(:filter_map)
|
||||
|
||||
def sum(accumulator = 0, &block)
|
||||
values = block_given? ? map(&block) : self
|
||||
values.inject(accumulator, :+)
|
||||
end unless Array.method_defined?(:sum)
|
||||
end
|
||||
end
|
||||
|
||||
module IOExtensions
|
||||
refine IO do
|
||||
# provides a fallback for rubies where IO#wait isn't implemented,
|
||||
# but IO#wait_readable and IO#wait_writable are.
|
||||
def wait(timeout = nil, _mode = :read_write)
|
||||
r, w = IO.select([self], [self], nil, timeout)
|
||||
|
||||
return unless r || w
|
||||
|
||||
self
|
||||
end unless IO.method_defined?(:wait) && IO.instance_method(:wait).arity == 2
|
||||
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
|
||||
|
@ -134,7 +134,7 @@ module HTTPX
|
||||
server_cert = @io.peer_cert
|
||||
|
||||
"#{super}\n\n" \
|
||||
"SSL connection using #{@io.ssl_version} / #{Array(@io.cipher).first}\n" \
|
||||
"SSL connection using #{@io.ssl_version} / #{Array(@io.cipher).first}\n" \
|
||||
"ALPN, server accepted to use #{protocol}\n" \
|
||||
"Server certificate:\n" \
|
||||
" subject: #{server_cert.subject}\n" \
|
||||
|
@ -194,15 +194,15 @@ module HTTPX
|
||||
server_cert = @peer_cert
|
||||
|
||||
"#{super}\n\n" \
|
||||
"SSL connection using #{@ctx.ssl_version} / #{Array(@ctx.cipher).first}\n" \
|
||||
"ALPN, server accepted to use #{protocol}\n" +
|
||||
"SSL connection using #{@ctx.ssl_version} / #{Array(@ctx.cipher).first}\n" \
|
||||
"ALPN, server accepted to use #{protocol}\n" +
|
||||
(if server_cert
|
||||
"Server certificate:\n" \
|
||||
" subject: #{server_cert.subject}\n" \
|
||||
" start date: #{server_cert.not_before}\n" \
|
||||
" expire date: #{server_cert.not_after}\n" \
|
||||
" issuer: #{server_cert.issuer}\n" \
|
||||
" SSL certificate verify ok."
|
||||
" subject: #{server_cert.subject}\n" \
|
||||
" start date: #{server_cert.not_before}\n" \
|
||||
" expire date: #{server_cert.not_after}\n" \
|
||||
" issuer: #{server_cert.issuer}\n" \
|
||||
" SSL certificate verify ok."
|
||||
else
|
||||
"SSL certificate verify failed."
|
||||
end
|
||||
|
@ -24,7 +24,16 @@ module HTTPX
|
||||
debug_stream << message
|
||||
end
|
||||
|
||||
if !Exception.instance_methods.include?(:full_message)
|
||||
if Exception.instance_methods.include?(:full_message)
|
||||
|
||||
def log_exception(ex, level: @options.debug_level, color: nil)
|
||||
return unless @options.debug
|
||||
return unless @options.debug_level >= level
|
||||
|
||||
log(level: level, color: color) { ex.full_message }
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def log_exception(ex, level: @options.debug_level, color: nil)
|
||||
return unless @options.debug
|
||||
@ -35,15 +44,6 @@ module HTTPX
|
||||
log(level: level, color: color) { message }
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def log_exception(ex, level: @options.debug_level, color: nil)
|
||||
return unless @options.debug
|
||||
return unless @options.debug_level >= level
|
||||
|
||||
log(level: level, color: color) { ex.full_message }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -81,9 +81,9 @@ module HTTPX
|
||||
end
|
||||
|
||||
def def_option(optname, *args, &block)
|
||||
if args.size.zero? && !block_given?
|
||||
if args.size.zero? && !block
|
||||
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
|
||||
def option_#{optname}(v); v; end
|
||||
def option_#{optname}(v); v; end # def option_smth(v); v; end
|
||||
OUT
|
||||
return
|
||||
end
|
||||
@ -93,15 +93,15 @@ module HTTPX
|
||||
|
||||
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."
|
||||
"Define module OptionsMethods and `def option_#{optname}(val)` instead."
|
||||
|
||||
if layout
|
||||
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
|
||||
def option_#{optname}(value)
|
||||
#{layout}
|
||||
end
|
||||
def option_#{optname}(value) # def option_origin(v)
|
||||
#{layout} # URI(v)
|
||||
end # end
|
||||
OUT
|
||||
elsif block_given?
|
||||
elsif interpreter
|
||||
define_method(:"option_#{optname}") do |value|
|
||||
instance_exec(value, &interpreter)
|
||||
end
|
||||
|
@ -75,16 +75,16 @@ module HTTPX
|
||||
|
||||
# canonical request
|
||||
creq = "#{request.verb.to_s.upcase}" \
|
||||
"\n#{request.canonical_path}" \
|
||||
"\n#{request.canonical_query}" \
|
||||
"\n#{canonical_headers}" \
|
||||
"\n#{signed_headers}" \
|
||||
"\n#{content_hashed}"
|
||||
"\n#{request.canonical_path}" \
|
||||
"\n#{request.canonical_query}" \
|
||||
"\n#{canonical_headers}" \
|
||||
"\n#{signed_headers}" \
|
||||
"\n#{content_hashed}"
|
||||
|
||||
credential_scope = "#{date}" \
|
||||
"/#{@region}" \
|
||||
"/#{@service}" \
|
||||
"/#{lower_provider_prefix}_request"
|
||||
"/#{@region}" \
|
||||
"/#{@service}" \
|
||||
"/#{lower_provider_prefix}_request"
|
||||
|
||||
algo_line = "#{upper_provider_prefix}-HMAC-#{@algorithm}"
|
||||
# string to sign
|
||||
|
@ -72,6 +72,8 @@ module HTTPX
|
||||
end
|
||||
|
||||
module ResponseBodyMethods
|
||||
using ArrayExtensions
|
||||
|
||||
attr_reader :encodings
|
||||
|
||||
def initialize(*)
|
||||
@ -90,7 +92,7 @@ module HTTPX
|
||||
Float::INFINITY
|
||||
end
|
||||
|
||||
@_inflaters = @headers.get("content-encoding").map do |encoding|
|
||||
@_inflaters = @headers.get("content-encoding").filter_map do |encoding|
|
||||
next if encoding == "identity"
|
||||
|
||||
inflater = @options.encodings.registry(encoding).inflater(compressed_length)
|
||||
@ -100,7 +102,7 @@ module HTTPX
|
||||
|
||||
@encodings << encoding
|
||||
inflater
|
||||
end.compact
|
||||
end
|
||||
|
||||
# this can happen if the only declared encoding is "identity"
|
||||
remove_instance_variable(:@_inflaters) if @_inflaters.empty?
|
||||
@ -134,7 +136,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def each(&blk)
|
||||
return enum_for(__method__) unless block_given?
|
||||
return enum_for(__method__) unless blk
|
||||
|
||||
return deflate(&blk) if @buffer.size.zero?
|
||||
|
||||
|
@ -55,7 +55,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def each(uri = nil, &blk)
|
||||
return enum_for(__method__, uri) unless block_given?
|
||||
return enum_for(__method__, uri) unless blk
|
||||
|
||||
return @cookies.each(&blk) unless uri
|
||||
|
||||
|
@ -143,9 +143,9 @@ module HTTPX
|
||||
|
||||
session_class = Class.new(self.class) do
|
||||
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
|
||||
def #{rpc_name}(input, **opts)
|
||||
rpc_execute("#{rpc_name}", input, **opts)
|
||||
end
|
||||
def #{rpc_name}(input, **opts) # def grpc_action(input, **opts)
|
||||
rpc_execute("#{rpc_name}", input, **opts) # rpc_execute("grpc_action", input, **opts)
|
||||
end # end
|
||||
OUT
|
||||
end
|
||||
|
||||
|
@ -17,7 +17,7 @@ module HTTPX
|
||||
|
||||
# lazy decodes a grpc stream response
|
||||
def stream(response, &block)
|
||||
return enum_for(__method__, response) unless block_given?
|
||||
return enum_for(__method__, response) unless block
|
||||
|
||||
response.each do |frame|
|
||||
decode(frame, encodings: response.headers.get("grpc-encoding"), encoders: response.encoders, &block)
|
||||
@ -57,7 +57,7 @@ module HTTPX
|
||||
|
||||
yield data
|
||||
|
||||
message = message.byteslice(5 + size..-1)
|
||||
message = message.byteslice((5 + size)..-1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,8 +29,8 @@ module HTTPX
|
||||
# in order not to break legacy code, we'll keep loading http/form_data for them.
|
||||
require "http/form_data"
|
||||
warn "httpx: http/form_data is no longer a requirement to use HTTPX :multipart plugin. See migration instructions under" \
|
||||
"https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes. \n\n" \
|
||||
"If you'd like to stop seeing this message, require 'http/form_data' yourself."
|
||||
"https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes. \n\n" \
|
||||
"If you'd like to stop seeing this message, require 'http/form_data' yourself."
|
||||
end
|
||||
rescue LoadError
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
return enum_for(__method__) unless block_given?
|
||||
return enum_for(__method__) unless block
|
||||
|
||||
raise Error, "response already streamed" if @response
|
||||
|
||||
|
@ -8,6 +8,7 @@ require "httpx/resolver"
|
||||
|
||||
module HTTPX
|
||||
class Pool
|
||||
using ArrayExtensions
|
||||
extend Forwardable
|
||||
|
||||
def_delegator :@timers, :after
|
||||
@ -162,7 +163,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def next_timeout
|
||||
@resolvers.values.reject(&:closed?).map(&:timeout).compact.min || @connections.map(&:timeout).compact.min
|
||||
@resolvers.values.reject(&:closed?).filter_map(&:timeout).min || @connections.filter_map(&:timeout).min
|
||||
end
|
||||
|
||||
def find_resolver_for(connection)
|
||||
|
@ -148,10 +148,10 @@ module HTTPX
|
||||
# :nocov:
|
||||
def inspect
|
||||
"#<HTTPX::Request:#{object_id} " \
|
||||
"#{@verb.to_s.upcase} " \
|
||||
"#{uri} " \
|
||||
"@headers=#{@headers} " \
|
||||
"@body=#{@body}>"
|
||||
"#{@verb.to_s.upcase} " \
|
||||
"#{uri} " \
|
||||
"@headers=#{@headers} " \
|
||||
"@body=#{@body}>"
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
@ -181,7 +181,7 @@ module HTTPX
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
return enum_for(__method__) unless block_given?
|
||||
return enum_for(__method__) unless block
|
||||
return if @body.nil?
|
||||
|
||||
body = stream(@body)
|
||||
@ -236,7 +236,7 @@ module HTTPX
|
||||
# :nocov:
|
||||
def inspect
|
||||
"#<HTTPX::Request::Body:#{object_id} " \
|
||||
"#{unbounded_body? ? "stream" : "@bytesize=#{bytesize}"}>"
|
||||
"#{unbounded_body? ? "stream" : "@bytesize=#{bytesize}"}>"
|
||||
end
|
||||
# :nocov:
|
||||
end
|
||||
|
@ -57,10 +57,10 @@ module HTTPX
|
||||
# :nocov:
|
||||
def inspect
|
||||
"#<Response:#{object_id} "\
|
||||
"HTTP/#{version} " \
|
||||
"@status=#{@status} " \
|
||||
"@headers=#{@headers} " \
|
||||
"@body=#{@body.bytesize}>"
|
||||
"HTTP/#{version} " \
|
||||
"@status=#{@status} " \
|
||||
"@headers=#{@headers} " \
|
||||
"@body=#{@body.bytesize}>"
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
@ -221,8 +221,8 @@ module HTTPX
|
||||
# :nocov:
|
||||
def inspect
|
||||
"#<HTTPX::Response::Body:#{object_id} " \
|
||||
"@state=#{@state} " \
|
||||
"@length=#{@length}>"
|
||||
"@state=#{@state} " \
|
||||
"@length=#{@length}>"
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
@ -321,7 +321,7 @@ module HTTPX
|
||||
else
|
||||
def to_s
|
||||
"#{@error.message} (#{@error.class})\n" \
|
||||
"#{@error.backtrace.join("\n") if @error.backtrace}"
|
||||
"#{@error.backtrace.join("\n") if @error.backtrace}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,20 +2,6 @@
|
||||
|
||||
require "io/wait"
|
||||
|
||||
module IOExtensions
|
||||
refine IO do
|
||||
# provides a fallback for rubies where IO#wait isn't implemented,
|
||||
# but IO#wait_readable and IO#wait_writable are.
|
||||
def wait(timeout = nil, _mode = :read_write)
|
||||
r, w = IO.select([self], [self], nil, timeout)
|
||||
|
||||
return unless r || w
|
||||
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class HTTPX::Selector
|
||||
READABLE = %i[rw r].freeze
|
||||
WRITABLE = %i[rw w].freeze
|
||||
@ -23,7 +9,7 @@ class HTTPX::Selector
|
||||
private_constant :READABLE
|
||||
private_constant :WRITABLE
|
||||
|
||||
using IOExtensions unless IO.method_defined?(:wait) && IO.instance_method(:wait).arity == 2
|
||||
using HTTPX::IOExtensions
|
||||
|
||||
def initialize
|
||||
@selectables = []
|
||||
|
@ -11,7 +11,7 @@ module HTTPX
|
||||
@options = self.class.default_options.merge(options)
|
||||
@responses = {}
|
||||
@persistent = @options.persistent
|
||||
wrap(&blk) if block_given?
|
||||
wrap(&blk) if blk
|
||||
end
|
||||
|
||||
def wrap
|
||||
|
@ -9,6 +9,7 @@ module HTTPX::Transcoder
|
||||
module_function
|
||||
|
||||
class Encoder
|
||||
using HTTPX::ArrayExtensions
|
||||
extend Forwardable
|
||||
|
||||
def_delegator :@raw, :to_s
|
||||
@ -21,7 +22,7 @@ module HTTPX::Transcoder
|
||||
if @raw.respond_to?(:bytesize)
|
||||
@raw.bytesize
|
||||
elsif @raw.respond_to?(:to_ary)
|
||||
@raw.map(&:bytesize).reduce(0, :+)
|
||||
@raw.sum(&:bytesize)
|
||||
elsif @raw.respond_to?(:size)
|
||||
@raw.size || Float::INFINITY
|
||||
elsif @raw.respond_to?(:length)
|
||||
|
@ -92,9 +92,9 @@ class HTTPXAwsSigv4Test < Minitest::Test
|
||||
)
|
||||
|
||||
expected_authorization = "" \
|
||||
"AWS4-HMAC-SHA256 Credential=akid/20120101/REGION/SERVICE/aws4_request, " \
|
||||
"SignedHeaders=bar;bar2;foo;host;x-amz-content-sha256;x-amz-date, " \
|
||||
"Signature=4a7d3e06d1950eb64a3daa1becaa8ba030d9099858516cb2fa4533fab4e8937d"
|
||||
"AWS4-HMAC-SHA256 Credential=akid/20120101/REGION/SERVICE/aws4_request, " \
|
||||
"SignedHeaders=bar;bar2;foo;host;x-amz-content-sha256;x-amz-date, " \
|
||||
"Signature=4a7d3e06d1950eb64a3daa1becaa8ba030d9099858516cb2fa4533fab4e8937d"
|
||||
assert request.headers["authorization"] == expected_authorization,
|
||||
"expected: \"#{expected_authorization}\", got \"#{request.headers["authorization"]}\" inspected"
|
||||
end
|
||||
|
@ -33,19 +33,19 @@ class HTTPTest < Minitest::Test
|
||||
|
||||
def test_verbose_log
|
||||
log = StringIO.new
|
||||
uri = build_uri("/get")
|
||||
uri = URI(build_uri("/get"))
|
||||
response = HTTPX.get(uri, debug: log, debug_level: 2)
|
||||
verify_status(response, 200)
|
||||
log_output = log.string
|
||||
# assert request headers
|
||||
assert log_output.match(%r{HEADLINE: "GET .+ HTTP/1\.1"})
|
||||
assert log_output.match(%r{HEADER: Accept: */*})
|
||||
assert log_output.match(/HEADER: Host: \w+/)
|
||||
assert log_output.match(/HEADER: Connection: close/)
|
||||
assert log_output.include?("HEADLINE: \"GET #{uri.path} HTTP/1.1\"")
|
||||
assert log_output.include?("HEADER: Accept: */*")
|
||||
assert log_output.include?("HEADER: Host: ")
|
||||
assert log_output.include?("HEADER: Connection: close")
|
||||
# assert response headers
|
||||
assert log_output.match(%r{HEADLINE: 200 HTTP/1\.1})
|
||||
assert log_output.match(/HEADER: content-type: \w+/)
|
||||
assert log_output.match(/HEADER: content-length: \d+/)
|
||||
assert log_output.include?("HEADLINE: 200 HTTP/1.1")
|
||||
assert log_output.include?("HEADER: content-type: ")
|
||||
assert log_output.include?("HEADER: content-length: ")
|
||||
end
|
||||
|
||||
def test_max_streams
|
||||
|
@ -55,27 +55,27 @@ class HTTPSTest < Minitest::Test
|
||||
verify_status(response, 200)
|
||||
log_output = log.string
|
||||
# assert tls output
|
||||
assert log_output.match(%r{SSL connection using TLSv\d+\.\d+ / \w+})
|
||||
assert log_output.match(/ALPN, server accepted to use h2/) unless RUBY_ENGINE == "jruby" || RUBY_VERSION < "2.3"
|
||||
assert log_output.match(/Server certificate:/)
|
||||
assert log_output.match(/ subject: .+/)
|
||||
assert log_output.match(/ start date: .+ UTC/)
|
||||
assert log_output.match(/ expire date: .+ UTC/)
|
||||
assert log_output.match(/ issuer: .+/)
|
||||
assert log_output.match(/ SSL certificate verify ok./)
|
||||
assert log_output.include?("SSL connection using TLSv")
|
||||
assert log_output.include?("ALPN, server accepted to use h2") unless RUBY_ENGINE == "jruby" || RUBY_VERSION < "2.3"
|
||||
assert log_output.include?("Server certificate:")
|
||||
assert log_output.include?(" subject: ")
|
||||
assert log_output.include?(" start date: ")
|
||||
assert log_output.include?(" expire date: ")
|
||||
assert log_output.include?(" issuer: ")
|
||||
assert log_output.include?(" SSL certificate verify ok")
|
||||
|
||||
return if RUBY_ENGINE == "jruby" || RUBY_VERSION < "2.3"
|
||||
|
||||
# assert request headers
|
||||
assert log_output.match(/HEADER: :scheme: https/)
|
||||
assert log_output.match(/HEADER: :method: GET/)
|
||||
assert log_output.match(/HEADER: :path: .+/)
|
||||
assert log_output.match(/HEADER: :authority: .+/)
|
||||
assert log_output.match(%r{HEADER: accept: */*})
|
||||
assert log_output.include?("HEADER: :scheme: https")
|
||||
assert log_output.include?("HEADER: :method: GET")
|
||||
assert log_output.include?("HEADER: :path: ")
|
||||
assert log_output.include?("HEADER: :authority: ")
|
||||
assert log_output.include?("HEADER: accept: */*")
|
||||
# assert response headers
|
||||
assert log_output.match(/HEADER: :status: 200/)
|
||||
assert log_output.match(/HEADER: content-type: \w+/)
|
||||
assert log_output.match(/HEADER: content-length: \d+/)
|
||||
assert log_output.include?("HEADER: :status: 200")
|
||||
assert log_output.include?("HEADER: content-type: ")
|
||||
assert log_output.include?("HEADER: content-length: ")
|
||||
end
|
||||
|
||||
unless RUBY_ENGINE == "jruby" || RUBY_VERSION < "2.3"
|
||||
|
@ -4,10 +4,11 @@ require_relative "test_helper"
|
||||
|
||||
class OptionsTest < Minitest::Test
|
||||
include HTTPX
|
||||
using HashExtensions
|
||||
|
||||
def test_options_unknown
|
||||
ex = assert_raises(Error) { Options.new(foo: "bar") }
|
||||
assert ex.message =~ /unknown option: foo/, ex.message
|
||||
assert ex.message == "unknown option: foo", ex.message
|
||||
end
|
||||
|
||||
def test_options_def_option_plain
|
||||
@ -126,7 +127,7 @@ class OptionsTest < Minitest::Test
|
||||
:persistent => false,
|
||||
:resolver_class => bar.resolver_class,
|
||||
:resolver_options => bar.resolver_options,
|
||||
}.reject { |_, value| value.nil? }
|
||||
}.compact
|
||||
|
||||
assert foo.merge(bar).to_hash == expected, "options haven't merged correctly"
|
||||
end unless ENV.key?("HTTPX_DEBUG")
|
||||
|
@ -7,7 +7,7 @@ class RequestTest < Minitest::Test
|
||||
|
||||
def test_request_unsupported_body
|
||||
ex = assert_raises(HTTPX::Error) { Request.new(:post, "http://example.com/", body: Object.new) }
|
||||
assert ex.message =~ /cannot determine size of body/
|
||||
assert ex.message.include?("cannot determine size of body")
|
||||
end
|
||||
|
||||
def test_request_verb
|
||||
|
@ -154,7 +154,7 @@ class ResponseTest < Minitest::Test
|
||||
assert form4_response.form == {}
|
||||
|
||||
error = assert_raises(HTTPX::Error) { form2_response.__send__(:decode, "bla") }
|
||||
assert error.message =~ /no decoder available for/, "failed with unexpected error"
|
||||
assert error.message.include?("no decoder available for"), "failed with unexpected error"
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -11,19 +11,19 @@ module ResponseHelpers
|
||||
|
||||
%w[header param].each do |meth|
|
||||
class_eval <<-DEFINE, __FILE__, __LINE__ + 1
|
||||
def verify_#{meth}(#{meth}s, key, expect)
|
||||
assert #{meth}s.key?(key), "#{meth}s don't contain the given key (\"\#{key}\", headers: \#{#{meth}s})"
|
||||
value = #{meth}s[key]
|
||||
if value.respond_to?(:start_with?)
|
||||
assert value.start_with?(expect), "#{meth} assertion failed: \#{key}=\#{value} (expected: \#{expect}})"
|
||||
else
|
||||
assert value == expect, "#{meth} assertion failed: \#{key}=\#{value.inspect} (expected: \#{expect.to_s})"
|
||||
end
|
||||
end
|
||||
def verify_#{meth}(#{meth}s, key, expect) # def verify_header(headers, key, expect)
|
||||
assert #{meth}s.key?(key), "#{meth}s don't contain the given key (\"\#{key}\", headers: \#{#{meth}s})" # assert headers.key?(key), "headers ...
|
||||
value = #{meth}s[key] # value = headers[key]
|
||||
if value.respond_to?(:start_with?) # if value.respond_to?(:start_with?)
|
||||
assert value.start_with?(expect), "#{meth} assertion failed: \#{key}=\#{value} (expected: \#{expect}})" # assert value.start_with?(expect), "headers assertion failed: ...
|
||||
else # else
|
||||
assert value == expect, "#{meth} assertion failed: \#{key}=\#{value.inspect} (expected: \#{expect.to_s})" # assert value == expect, "headers assertion failed: ...
|
||||
end # end
|
||||
end # end
|
||||
|
||||
def verify_no_#{meth}(#{meth}s, key)
|
||||
assert !#{meth}s.key?(key), "#{meth}s contains the given key (" + key + ": \#{#{meth}s[key].inspect})"
|
||||
end
|
||||
def verify_no_#{meth}(#{meth}s, key) # def verify_no_header(headers, key)
|
||||
assert !#{meth}s.key?(key), "#{meth}s contains the given key (" + key + ": \#{#{meth}s[key].inspect})" # assert !headers.key?(key), "headers contains ...
|
||||
end # end
|
||||
DEFINE
|
||||
end
|
||||
|
||||
|
@ -115,7 +115,7 @@ module Requests
|
||||
stub = grpc.build_stub("localhost:#{server_port}")
|
||||
|
||||
error = assert_raises(HTTPX::Error) { stub.execute("an_rpc_method", input).to_s }
|
||||
assert error.message =~ /oh crap/
|
||||
assert error.message.include?("oh crap")
|
||||
end
|
||||
|
||||
def test_plugin_grpc_cancellation_on_server_error
|
||||
|
@ -11,11 +11,11 @@ class NTLMServer < TestServer
|
||||
case authorization
|
||||
when /^NTLMSSP\000\001/
|
||||
type2 = "TlRMTVNTUAACAAAADAAMADAAAAABAoEAASNFZ4mr" \
|
||||
"ze8AAAAAAAAAAGIAYgA8AAAARABPAE0AQQBJAE4A" \
|
||||
"AgAMAEQATwBNAEEASQBOAAEADABTAEUAUgBWAEUA" \
|
||||
"UgAEABQAZABvAG0AYQBpAG4ALgBjAG8AbQADACIA" \
|
||||
"cwBlAHIAdgBlAHIALgBkAG8AbQBhAGkAbgAuAGMA" \
|
||||
"bwBtAAAAAAA="
|
||||
"ze8AAAAAAAAAAGIAYgA8AAAARABPAE0AQQBJAE4A" \
|
||||
"AgAMAEQATwBNAEEASQBOAAEADABTAEUAUgBWAEUA" \
|
||||
"UgAEABQAZABvAG0AYQBpAG4ALgBjAG8AbQADACIA" \
|
||||
"cwBlAHIAdgBlAHIALgBkAG8AbQBhAGkAbgAuAGMA" \
|
||||
"bwBtAAAAAAA="
|
||||
|
||||
res["WWW-Authenticate"] = "NTLM #{type2}"
|
||||
res.status = 401
|
||||
|
Loading…
x
Reference in New Issue
Block a user