Class: HttpLoader::Client::TargetManager
- Inherits:
-
Object
- Object
- HttpLoader::Client::TargetManager
- Extended by:
- T::Sig
- Defined in:
- lib/http_loader/client/target_manager.rb
Overview
Manages URI contexts, IPs, proxies, and HTTPS resolution.
Instance Method Summary collapse
- #apply_proxy!(opts, client_index) ⇒ Object
- #context_for(client_index) ⇒ Object
- #contexts ⇒ Object
- #http_opts_for(client_index, args) ⇒ Object
-
#initialize(config) ⇒ TargetManager
constructor
A new instance of TargetManager.
- #protocol_label ⇒ Object
Constructor Details
#initialize(config) ⇒ TargetManager
Returns a new instance of TargetManager.
15 16 17 18 |
# File 'lib/http_loader/client/target_manager.rb', line 15 def initialize(config) @config = config @target_contexts = T.let(build_target_contexts, T::Array[T::Hash[Symbol, T.untyped]]) end |
Instance Method Details
#apply_proxy!(opts, client_index) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/http_loader/client/target_manager.rb', line 54 def apply_proxy!(opts, client_index) pool = @config.proxy_pool proxy_uri = URI.parse(pool[client_index % pool.size]) opts[:proxy_address] = proxy_uri.host opts[:proxy_port] = proxy_uri.port opts[:proxy_user] = proxy_uri.user if proxy_uri.user opts[:proxy_pass] = proxy_uri.password if proxy_uri.password end |
#context_for(client_index) ⇒ Object
39 40 41 |
# File 'lib/http_loader/client/target_manager.rb', line 39 def context_for(client_index) T.must(@target_contexts[client_index % @target_contexts.size]) end |
#contexts ⇒ Object
34 35 36 |
# File 'lib/http_loader/client/target_manager.rb', line 34 def contexts @target_contexts end |
#http_opts_for(client_index, args) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/http_loader/client/target_manager.rb', line 44 def http_opts_for(client_index, args) http_opts = args.dup bind_ips = @config.bind_ips http_opts[:local_host] = bind_ips[client_index % bind_ips.size] if bind_ips.any? apply_proxy!(http_opts, client_index) if @config.proxy_pool.any? http_opts end |
#protocol_label ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/http_loader/client/target_manager.rb', line 21 def protocol_label if @config.target_urls.size > 1 "MULTIPLE TARGETS (#{@config.target_urls.size})" elsif @config.target_urls.size == 1 "EXTERNAL #{T.cast(T.must(@target_contexts.first)[:uri], URI::Generic).scheme&.upcase}" elsif @config.use_https 'HTTPS' else 'HTTP' end end |