mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-09 00:02:50 -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/options"
|
||||||
require "httpx/chainable"
|
require "httpx/chainable"
|
||||||
|
|
||||||
require "mutex_m"
|
|
||||||
# Top-Level Namespace
|
# Top-Level Namespace
|
||||||
#
|
#
|
||||||
module HTTPX
|
module HTTPX
|
||||||
@ -31,16 +30,17 @@ module HTTPX
|
|||||||
#
|
#
|
||||||
module Plugins
|
module Plugins
|
||||||
@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
|
# 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.
|
# it from the load path under "httpx/plugins/" directory.
|
||||||
#
|
#
|
||||||
def self.load_plugin(name)
|
def self.load_plugin(name)
|
||||||
h = @plugins
|
h = @plugins
|
||||||
unless (plugin = h.synchronize { h[name] })
|
m = @plugins_mutex
|
||||||
|
unless (plugin = m.synchronize { h[name] })
|
||||||
require "httpx/plugins/#{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
|
end
|
||||||
plugin
|
plugin
|
||||||
end
|
end
|
||||||
@ -49,7 +49,8 @@ module HTTPX
|
|||||||
#
|
#
|
||||||
def self.register_plugin(name, mod)
|
def self.register_plugin(name, mod)
|
||||||
h = @plugins
|
h = @plugins
|
||||||
h.synchronize { h[name] = mod }
|
m = @plugins_mutex
|
||||||
|
m.synchronize { h[name] = mod }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ require "strscan"
|
|||||||
|
|
||||||
module HTTPX
|
module HTTPX
|
||||||
module AltSvc
|
module AltSvc
|
||||||
@altsvc_mutex = Mutex.new
|
@altsvc_mutex = Thread::Mutex.new
|
||||||
@altsvcs = Hash.new { |h, k| h[k] = [] }
|
@altsvcs = Hash.new { |h, k| h[k] = [] }
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "mutex_m"
|
|
||||||
|
|
||||||
module HTTPX::Plugins::CircuitBreaker
|
module HTTPX::Plugins::CircuitBreaker
|
||||||
using HTTPX::URIExtensions
|
using HTTPX::URIExtensions
|
||||||
|
|
||||||
@ -15,17 +13,17 @@ module HTTPX::Plugins::CircuitBreaker
|
|||||||
options.circuit_breaker_half_open_drip_rate
|
options.circuit_breaker_half_open_drip_rate
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@circuits.extend(Mutex_m)
|
@circuits_mutex = Thread::Mutex.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_open(uri, response)
|
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)
|
circuit.try_open(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_close(uri)
|
def try_close(uri)
|
||||||
circuit = @circuits.synchronize do
|
circuit = @circuits_mutex.synchronize do
|
||||||
return unless @circuits.key?(uri.origin) || @circuits.key?(uri.to_s)
|
return unless @circuits.key?(uri.origin) || @circuits.key?(uri.to_s)
|
||||||
|
|
||||||
get_circuit_for_uri(uri)
|
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 circuit is open, it'll respond with the stored response.
|
||||||
# if not, nil.
|
# if not, nil.
|
||||||
def try_respond(request)
|
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
|
circuit.respond
|
||||||
end
|
end
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "mutex_m"
|
|
||||||
|
|
||||||
module HTTPX::Plugins
|
module HTTPX::Plugins
|
||||||
module ResponseCache
|
module ResponseCache
|
||||||
class Store
|
class Store
|
||||||
def initialize
|
def initialize
|
||||||
@store = {}
|
@store = {}
|
||||||
@store.extend(Mutex_m)
|
@store_mutex = Thread::Mutex.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
@store.synchronize { @store.clear }
|
@store_mutex.synchronize { @store.clear }
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup(request)
|
def lookup(request)
|
||||||
@ -66,7 +64,7 @@ module HTTPX::Plugins
|
|||||||
end
|
end
|
||||||
|
|
||||||
def _get(request)
|
def _get(request)
|
||||||
@store.synchronize do
|
@store_mutex.synchronize do
|
||||||
responses = @store[request.response_cache_key]
|
responses = @store[request.response_cache_key]
|
||||||
|
|
||||||
return unless responses
|
return unless responses
|
||||||
@ -80,7 +78,7 @@ module HTTPX::Plugins
|
|||||||
end
|
end
|
||||||
|
|
||||||
def _set(request, response)
|
def _set(request, response)
|
||||||
@store.synchronize do
|
@store_mutex.synchronize do
|
||||||
responses = (@store[request.response_cache_key] ||= [])
|
responses = (@store[request.response_cache_key] ||= [])
|
||||||
|
|
||||||
responses.reject! do |res|
|
responses.reject! do |res|
|
||||||
|
@ -13,10 +13,10 @@ module HTTPX
|
|||||||
require "httpx/resolver/https"
|
require "httpx/resolver/https"
|
||||||
require "httpx/resolver/multi"
|
require "httpx/resolver/multi"
|
||||||
|
|
||||||
@lookup_mutex = Mutex.new
|
@lookup_mutex = Thread::Mutex.new
|
||||||
@lookups = Hash.new { |h, k| h[k] = [] }
|
@lookups = Hash.new { |h, k| h[k] = [] }
|
||||||
|
|
||||||
@identifier_mutex = Mutex.new
|
@identifier_mutex = Thread::Mutex.new
|
||||||
@identifier = 1
|
@identifier = 1
|
||||||
@system_resolver = Resolv::Hosts.new
|
@system_resolver = Resolv::Hosts.new
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ module HTTPX
|
|||||||
module CircuitBreaker
|
module CircuitBreaker
|
||||||
|
|
||||||
class CircuitStore
|
class CircuitStore
|
||||||
@circuits: Hash[String, Circuit] & Mutex_m
|
@circuits: Hash[String, Circuit]
|
||||||
|
|
||||||
|
@circuits_mutex: Thread::Mutex
|
||||||
|
|
||||||
def try_open: (uri uri, response response) -> response?
|
def try_open: (uri uri, response response) -> response?
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@ module HTTPX
|
|||||||
def self?.cached_response?: (response response) -> bool
|
def self?.cached_response?: (response response) -> bool
|
||||||
|
|
||||||
class Store
|
class Store
|
||||||
@store: Hash[String, Array[Response]] & Mutex_m
|
@store: Hash[String, Array[Response]]
|
||||||
|
|
||||||
|
@store_mutex: Thread::Mutex
|
||||||
|
|
||||||
def lookup: (Request request) -> Response?
|
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 RUBYOPT="$RUBYOPT -rbundler/setup -rrbs/test/setup"
|
||||||
export RBS_TEST_RAISE=true
|
export RBS_TEST_RAISE=true
|
||||||
export RBS_TEST_LOGLEVEL=error
|
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*"
|
export RBS_TEST_TARGET="HTTP*"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user