mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-07 00:05:02 -04:00
Remove dependency on mutex_m
This commit is contained in:
parent
7345c19d5d
commit
ac21f563de
11
lib/httpx.rb
11
lib/httpx.rb
@ -20,7 +20,6 @@ require "httpx/response"
|
||||
require "httpx/options"
|
||||
require "httpx/chainable"
|
||||
|
||||
require "mutex_m"
|
||||
# Top-Level Namespace
|
||||
#
|
||||
module HTTPX
|
||||
@ -31,16 +30,17 @@ module HTTPX
|
||||
#
|
||||
module Plugins
|
||||
@plugins = {}
|
||||
@plugins.extend(Mutex_m)
|
||||
@plugins_mutex = Thread::Mutex.new
|
||||
|
||||
# Loads a plugin based on a name. If the plugin hasn't been loaded, tries to load
|
||||
# it from the load path under "httpx/plugins/" directory.
|
||||
#
|
||||
def self.load_plugin(name)
|
||||
h = @plugins
|
||||
unless (plugin = h.synchronize { h[name] })
|
||||
m = @plugins_mutex
|
||||
unless (plugin = m.synchronize { h[name] })
|
||||
require "httpx/plugins/#{name}"
|
||||
raise "Plugin #{name} hasn't been registered" unless (plugin = h.synchronize { h[name] })
|
||||
raise "Plugin #{name} hasn't been registered" unless (plugin = m.synchronize { h[name] })
|
||||
end
|
||||
plugin
|
||||
end
|
||||
@ -49,7 +49,8 @@ module HTTPX
|
||||
#
|
||||
def self.register_plugin(name, mod)
|
||||
h = @plugins
|
||||
h.synchronize { h[name] = mod }
|
||||
m = @plugins_mutex
|
||||
m.synchronize { h[name] = mod }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,7 @@ require "strscan"
|
||||
|
||||
module HTTPX
|
||||
module AltSvc
|
||||
@altsvc_mutex = Mutex.new
|
||||
@altsvc_mutex = Thread::Mutex.new
|
||||
@altsvcs = Hash.new { |h, k| h[k] = [] }
|
||||
|
||||
module_function
|
||||
|
@ -1,7 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "mutex_m"
|
||||
|
||||
module HTTPX::Plugins::CircuitBreaker
|
||||
using HTTPX::URIExtensions
|
||||
|
||||
@ -15,17 +13,17 @@ module HTTPX::Plugins::CircuitBreaker
|
||||
options.circuit_breaker_half_open_drip_rate
|
||||
)
|
||||
end
|
||||
@circuits.extend(Mutex_m)
|
||||
@circuits_mutex = Thread::Mutex.new
|
||||
end
|
||||
|
||||
def try_open(uri, response)
|
||||
circuit = @circuits.synchronize { get_circuit_for_uri(uri) }
|
||||
circuit = @circuits_mutex.synchronize { get_circuit_for_uri(uri) }
|
||||
|
||||
circuit.try_open(response)
|
||||
end
|
||||
|
||||
def try_close(uri)
|
||||
circuit = @circuits.synchronize do
|
||||
circuit = @circuits_mutex.synchronize do
|
||||
return unless @circuits.key?(uri.origin) || @circuits.key?(uri.to_s)
|
||||
|
||||
get_circuit_for_uri(uri)
|
||||
@ -37,7 +35,7 @@ module HTTPX::Plugins::CircuitBreaker
|
||||
# if circuit is open, it'll respond with the stored response.
|
||||
# if not, nil.
|
||||
def try_respond(request)
|
||||
circuit = @circuits.synchronize { get_circuit_for_uri(request.uri) }
|
||||
circuit = @circuits_mutex.synchronize { get_circuit_for_uri(request.uri) }
|
||||
|
||||
circuit.respond
|
||||
end
|
||||
|
@ -1,17 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "mutex_m"
|
||||
|
||||
module HTTPX::Plugins
|
||||
module ResponseCache
|
||||
class Store
|
||||
def initialize
|
||||
@store = {}
|
||||
@store.extend(Mutex_m)
|
||||
@store_mutex = Thread::Mutex.new
|
||||
end
|
||||
|
||||
def clear
|
||||
@store.synchronize { @store.clear }
|
||||
@store_mutex.synchronize { @store.clear }
|
||||
end
|
||||
|
||||
def lookup(request)
|
||||
@ -66,7 +64,7 @@ module HTTPX::Plugins
|
||||
end
|
||||
|
||||
def _get(request)
|
||||
@store.synchronize do
|
||||
@store_mutex.synchronize do
|
||||
responses = @store[request.response_cache_key]
|
||||
|
||||
return unless responses
|
||||
@ -80,7 +78,7 @@ module HTTPX::Plugins
|
||||
end
|
||||
|
||||
def _set(request, response)
|
||||
@store.synchronize do
|
||||
@store_mutex.synchronize do
|
||||
responses = (@store[request.response_cache_key] ||= [])
|
||||
|
||||
responses.reject! do |res|
|
||||
|
@ -13,10 +13,10 @@ module HTTPX
|
||||
require "httpx/resolver/https"
|
||||
require "httpx/resolver/multi"
|
||||
|
||||
@lookup_mutex = Mutex.new
|
||||
@lookup_mutex = Thread::Mutex.new
|
||||
@lookups = Hash.new { |h, k| h[k] = [] }
|
||||
|
||||
@identifier_mutex = Mutex.new
|
||||
@identifier_mutex = Thread::Mutex.new
|
||||
@identifier = 1
|
||||
@system_resolver = Resolv::Hosts.new
|
||||
|
||||
|
@ -3,7 +3,9 @@ module HTTPX
|
||||
module CircuitBreaker
|
||||
|
||||
class CircuitStore
|
||||
@circuits: Hash[String, Circuit] & Mutex_m
|
||||
@circuits: Hash[String, Circuit]
|
||||
|
||||
@circuits_mutex: Thread::Mutex
|
||||
|
||||
def try_open: (uri uri, response response) -> response?
|
||||
|
||||
|
@ -9,7 +9,9 @@ module HTTPX
|
||||
def self?.cached_response?: (response response) -> bool
|
||||
|
||||
class Store
|
||||
@store: Hash[String, Array[Response]] & Mutex_m
|
||||
@store: Hash[String, Array[Response]]
|
||||
|
||||
@store_mutex: Thread::Mutex
|
||||
|
||||
def lookup: (Request request) -> Response?
|
||||
|
||||
|
@ -65,7 +65,7 @@ if [[ "$RUBY_ENGINE" = "ruby" ]] && [[ ${RUBY_VERSION:0:1} = "3" ]] && [[ ! $RUB
|
||||
export RUBYOPT="$RUBYOPT -rbundler/setup -rrbs/test/setup"
|
||||
export RBS_TEST_RAISE=true
|
||||
export RBS_TEST_LOGLEVEL=error
|
||||
export RBS_TEST_OPT="-Isig -rset -rmutex_m -rforwardable -ruri -rjson -ripaddr -rpathname -rtime -rtimeout -rresolv -rsocket -ropenssl -rbase64 -rzlib -rcgi -rdigest -rhttp-2-next"
|
||||
export RBS_TEST_OPT="-Isig -rset -rforwardable -ruri -rjson -ripaddr -rpathname -rtime -rtimeout -rresolv -rsocket -ropenssl -rbase64 -rzlib -rcgi -rdigest -rhttp-2-next"
|
||||
export RBS_TEST_TARGET="HTTP*"
|
||||
fi
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user