Compare commits

...

6 Commits

Author SHA1 Message Date
HoneyryderChuck
325f7141c8 promoting HTTPX::Response::Body#encoding to public API 2022-12-21 00:46:14 +00:00
HoneyryderChuck
d09b107314 dealing with datadog breaking change better 2022-12-21 00:45:26 +00:00
HoneyryderChuck
e301811196 fixed datadog recent change for error tag 2022-12-21 00:31:42 +00:00
HoneyryderChuck
9842511594 more linting... 2022-12-20 22:58:57 +00:00
HoneyryderChuck
d629402245 linting 2022-12-20 22:28:07 +00:00
HoneyryderChuck
9b89cb3331 commenting extensions 2022-12-20 22:27:59 +00:00
9 changed files with 27 additions and 11 deletions

View File

@ -50,11 +50,11 @@ rdoc_opts = ["--line-numbers", "--title", "HTTPX: An HTTP client library for rub
begin begin
gem "hanna-nouveau" gem "hanna-nouveau"
rdoc_opts.concat(["-f", "hanna"]) rdoc_opts.push("-f", "hanna")
rescue Gem::LoadError rescue Gem::LoadError
end end
rdoc_opts.concat(["--main", "README.md"]) rdoc_opts.push("--main", "README.md")
RDOC_FILES = %w[README.md lib/**/*.rb] + Dir["doc/*.rdoc"] + Dir["doc/release_notes/*.md"] RDOC_FILES = %w[README.md lib/**/*.rb] + Dir["doc/*.rdoc"] + Dir["doc/release_notes/*.md"]
RDoc::Task.new do |rdoc| RDoc::Task.new do |rdoc|

View File

@ -197,14 +197,21 @@ class DatadogTest < Minitest::Test
assert span.get_tag("out.port") == "80" assert span.get_tag("out.port") == "80"
assert span.get_tag("http.method") == verb assert span.get_tag("http.method") == verb
assert span.get_tag("http.url") == uri.path assert span.get_tag("http.url") == uri.path
error_tag = if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.8.0"
"error.message"
else
"error.msg"
end
if error if error
assert span.get_tag("error.type") == error assert span.get_tag("error.type") == error
assert !span.get_tag("error.msg").nil? assert !span.get_tag(error_tag).nil?
assert span.status == 1 assert span.status == 1
elsif response.status >= 400 elsif response.status >= 400
assert span.get_tag("http.status_code") == response.status.to_s assert span.get_tag("http.status_code") == response.status.to_s
assert span.get_tag("error.type") == "HTTPX::HTTPError" assert span.get_tag("error.type") == "HTTPX::HTTPError"
assert !span.get_tag("error.msg").nil? assert !span.get_tag(error_tag).nil?
assert span.status == 1 assert span.status == 1
else else
assert span.status.zero? assert span.status.zero?

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0" if defined?(DDTrace) && DDTrace::VERSION::STRING >= "1.0.0"
require "datadog/tracing/contrib/integration" require "datadog/tracing/contrib/integration"
require "datadog/tracing/contrib/configuration/settings" require "datadog/tracing/contrib/configuration/settings"
require "datadog/tracing/contrib/patcher" require "datadog/tracing/contrib/patcher"

View File

@ -95,7 +95,7 @@ module HTTPX::Plugins
end end
Sentry.register_patch do Sentry.register_patch do
sentry_session = ::HTTPX.plugin(HTTPX::Plugins::Sentry) sentry_session = HTTPX.plugin(HTTPX::Plugins::Sentry)
HTTPX.send(:remove_const, :Session) HTTPX.send(:remove_const, :Session)
HTTPX.send(:const_set, :Session, sentry_session.class) HTTPX.send(:const_set, :Session, sentry_session.class)

View File

@ -55,6 +55,7 @@ module HTTPX
end end
module NumericExtensions module NumericExtensions
# Ruby 2.4 backport
refine Numeric do refine Numeric do
def infinite? def infinite?
self == Float::INFINITY self == Float::INFINITY
@ -64,6 +65,7 @@ module HTTPX
module StringExtensions module StringExtensions
refine String do refine String do
# Ruby 2.5 backport
def delete_suffix!(suffix) def delete_suffix!(suffix)
suffix = Backports.coerce_to_str(suffix) suffix = Backports.coerce_to_str(suffix)
chomp! if frozen? chomp! if frozen?
@ -80,6 +82,7 @@ module HTTPX
module HashExtensions module HashExtensions
refine Hash do refine Hash do
# Ruby 2.4 backport
def compact def compact
h = {} h = {}
each do |key, value| each do |key, value|
@ -93,7 +96,7 @@ module HTTPX
module ArrayExtensions module ArrayExtensions
module FilterMap module FilterMap
refine Array do refine Array do
# Ruby 2.7 backport
def filter_map def filter_map
return to_enum(:filter_map) unless block_given? return to_enum(:filter_map) unless block_given?
@ -107,6 +110,7 @@ module HTTPX
module Sum module Sum
refine Array do refine Array do
# Ruby 2.6 backport
def sum(accumulator = 0, &block) def sum(accumulator = 0, &block)
values = block_given? ? map(&block) : self values = block_given? ? map(&block) : self
values.inject(accumulator, :+) values.inject(accumulator, :+)
@ -116,6 +120,7 @@ module HTTPX
module Intersect module Intersect
refine Array do refine Array do
# Ruby 3.1 backport
def intersect?(arr) def intersect?(arr)
if size < arr.size if size < arr.size
smaller = self smaller = self
@ -130,6 +135,7 @@ module HTTPX
module IOExtensions module IOExtensions
refine IO do refine IO do
# Ruby 2.3 backport
# provides a fallback for rubies where IO#wait isn't implemented, # provides a fallback for rubies where IO#wait isn't implemented,
# but IO#wait_readable and IO#wait_writable are. # but IO#wait_readable and IO#wait_writable are.
def wait(timeout = nil, _mode = :read_write) def wait(timeout = nil, _mode = :read_write)
@ -144,6 +150,7 @@ module HTTPX
module RegexpExtensions module RegexpExtensions
refine(Regexp) do refine(Regexp) do
# Ruby 2.4 backport
def match?(*args) def match?(*args)
!match(*args).nil? !match(*args).nil?
end end
@ -151,6 +158,7 @@ module HTTPX
end end
module URIExtensions module URIExtensions
# uri 0.11 backport, ships with ruby 3.1
refine URI::Generic do refine URI::Generic do
def non_ascii_hostname def non_ascii_hostname
@non_ascii_hostname @non_ascii_hostname

View File

@ -128,6 +128,8 @@ module HTTPX
end end
class Body class Body
attr_reader :encoding
def initialize(response, options) def initialize(response, options)
@response = response @response = response
@headers = response.headers @headers = response.headers

View File

@ -38,7 +38,6 @@ module HTTPX::Transcoder
begin begin
require "nokogiri" require "nokogiri"
# rubocop:disable Lint/DuplicateMethods
def decode(response) def decode(response)
content_type = response.content_type.mime_type content_type = response.content_type.mime_type
@ -51,7 +50,6 @@ module HTTPX::Transcoder
raise HTTPX::Error, "\"nokogiri\" is required in order to decode XML" raise HTTPX::Error, "\"nokogiri\" is required in order to decode XML"
end end
end end
# rubocop:enable Lint/DuplicateMethods
end end
register "xml", Xml register "xml", Xml
end end

View File

@ -48,13 +48,14 @@ module HTTPX
include _ToS include _ToS
include _ToStr include _ToStr
attr_reader encoding: String
@response: Response @response: Response
@headers: Headers @headers: Headers
@options: Options @options: Options
@state: :idle | :memory | :buffer | :closed @state: :idle | :memory | :buffer | :closed
@threshold_size: Integer @threshold_size: Integer
@window_size: Integer @window_size: Integer
@encoding: String
@length: Integer @length: Integer
@buffer: StringIO | Tempfile | nil @buffer: StringIO | Tempfile | nil

View File

@ -3,7 +3,7 @@
Signal.trap("USR2") do Signal.trap("USR2") do
warn "starting..." warn "starting..."
Thread.list.each do |thread| Thread.list.each do |thread|
warn "Thread TID-#{(thread.object_id ^ ::Process.pid).to_s(36)} #{thread.name}" warn "Thread TID-#{(thread.object_id ^ Process.pid).to_s(36)} #{thread.name}"
warn thread.backtrace || "<no backtrace available>" warn thread.backtrace || "<no backtrace available>"
end end
end end