Class: SplitIoClient::FaradayAdapter::PatchedNetHttpPersistent
- Inherits:
-
Faraday::Adapter::NetHttpPersistent
- Object
- Faraday::Adapter::NetHttpPersistent
- SplitIoClient::FaradayAdapter::PatchedNetHttpPersistent
- Defined in:
- lib/splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent.rb
Instance Method Summary collapse
-
#net_http_connection(env) ⇒ Object
Borrowed directly from the latest ‘NetHttpPersistent` adapter implementation.
- #proxy_uri(env) ⇒ Object
- #with_net_http_connection(env) {|net_http_connection(env)| ... } ⇒ Object
Instance Method Details
#net_http_connection(env) ⇒ Object
Borrowed directly from the latest ‘NetHttpPersistent` adapter implementation.
github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http_persistent.rb
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent.rb', line 11 def net_http_connection(env) @cached_connection ||= if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name] Net::HTTP::Persistent.new(name: 'Faraday') else Net::HTTP::Persistent.new('Faraday') end proxy_uri = proxy_uri(env) @cached_connection.proxy = proxy_uri if @cached_connection.proxy_uri != proxy_uri @cached_connection end |
#proxy_uri(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent.rb', line 24 def proxy_uri(env) proxy_uri = nil if (proxy = env[:request][:proxy]) proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s) proxy_uri.user = proxy_uri.password = nil # awful patch for net-http-persistent 2.8 not unescaping user/password ( class << proxy_uri; self; end).class_eval do define_method(:user) { proxy[:user] } define_method(:password) { proxy[:password] } end if proxy[:user] end proxy_uri end |
#with_net_http_connection(env) {|net_http_connection(env)| ... } ⇒ Object
41 42 43 |
# File 'lib/splitclient-rb/engine/api/faraday_adapter/patched_net_http_persistent.rb', line 41 def with_net_http_connection(env) yield net_http_connection(env) end |