removing usage of global unshareable object in default options

This commit is contained in:
HoneyryderChuck 2024-11-04 11:51:17 +00:00
parent 594f6056da
commit c019f1b3a7
4 changed files with 9 additions and 7 deletions

View File

@ -13,11 +13,14 @@ module HTTPX
white: 37,
}.freeze
USE_DEBUG_LOG = ENV.key?("HTTPX_DEBUG")
def log(level: @options.debug_level, color: nil, &msg)
return unless @options.debug
return unless @options.debug_level >= level
debug_stream = @options.debug
debug_stream = @options.debug || ($stderr if USE_DEBUG_LOG)
return unless debug_stream
message = (+"" << msg.call << "\n")
message = "\e[#{COLORS[color]}m#{message}\e[0m" if color && debug_stream.respond_to?(:isatty) && debug_stream.isatty
@ -25,9 +28,6 @@ module HTTPX
end
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

View File

@ -29,7 +29,7 @@ module HTTPX
DEFAULT_OPTIONS = {
:max_requests => Float::INFINITY,
:debug => ENV.key?("HTTPX_DEBUG") ? STDERR : nil,
:debug => nil,
:debug_level => (ENV["HTTPX_DEBUG"] || 1).to_i,
:ssl => EMPTY_HASH,
:http2_settings => { settings_enable_push: 0 }.freeze,

View File

@ -4,6 +4,8 @@ module HTTPX
end
module Loggable
USE_DEBUG_LOGS: bool
COLORS: Hash[Symbol, Integer]
def log: (?level: Integer?, ?color: Symbol?) { () -> String } -> void

View File

@ -136,7 +136,7 @@ module HTTPX
def do_initialize: (?options options) -> void
def access_option: (Hash | Object obj, Symbol k, Hash[Symbol, Symbol] ivar_map)
def access_option: (Hash | Object | nil obj, Symbol k, Hash[Symbol, Symbol]? ivar_map) -> untyped
end
type options = Options | Hash[Symbol, untyped]