module Azure::Storage::Common::Core::HttpClient
Public Instance Methods
agents(uri)
click to toggle source
Returns the http agent based on uri @param uri [URI|String] the base uri (scheme, host, port) of the http endpoint @return [Net::HTTP] http agent for a given uri
# File lib/azure/storage/common/core/http_client.rb, line 32 def agents(uri) uri = URI(uri) unless uri.is_a? URI key = uri.host @agents ||= {} unless @agents.key?(key) @agents[key] = build_http(uri) else reuse_agent!(@agents[key]) end @agents[key] end
reset_agents!()
click to toggle source
Empties all the http agents
# File lib/azure/storage/common/core/http_client.rb, line 46 def reset_agents! @agents = nil end
Private Instance Methods
build_http(uri)
click to toggle source
# File lib/azure/storage/common/core/http_client.rb, line 58 def build_http(uri) ssl_options = {} if uri.is_a?(URI) && uri.scheme.downcase == "https" ssl_options[:version] = self.ssl_version if self.ssl_version # min_version and max_version only supported in ruby 2.5 ssl_options[:min_version] = self.ssl_min_version if self.ssl_min_version ssl_options[:max_version] = self.ssl_max_version if self.ssl_max_version ssl_options[:ca_file] = self.ca_file if self.ca_file ssl_options[:verify] = true end proxy_options = if ENV["HTTP_PROXY"] URI::parse(ENV["HTTP_PROXY"]) elsif ENV["HTTPS_PROXY"] URI::parse(ENV["HTTPS_PROXY"]) end || nil Faraday.new(uri, ssl: ssl_options, proxy: proxy_options) do |conn| conn.use FaradayMiddleware::FollowRedirects conn.adapter :net_http_persistent, pool_size: 5 do |http| # yields Net::HTTP::Persistent http.idle_timeout = 100 end end end
reuse_agent!(agent)
click to toggle source
Empties all information that cannot be reused.
# File lib/azure/storage/common/core/http_client.rb, line 53 def reuse_agent!(agent) agent.params.clear agent.headers.clear end