Skip to content

Commit

Permalink
removing usage of global unshareable object in default options
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed Nov 19, 2024
1 parent 594f605 commit c019f1b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/httpx/loggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ module Loggable
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
debug_stream << message
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
Expand Down
2 changes: 1 addition & 1 deletion lib/httpx/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Options

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,
Expand Down
2 changes: 2 additions & 0 deletions sig/loggable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sig/options.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit c019f1b

Please sign in to comment.