Class: HTTParty::Persistent::ConnectionAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/httparty/persistent/connection_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#persistent_httpObject

Returns the value of attribute persistent_http.



6
7
8
# File 'lib/httparty/persistent/connection_adapter.rb', line 6

def persistent_http
  @persistent_http
end

Instance Method Details

#build_persistent_http(uri, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/httparty/persistent/connection_adapter.rb', line 15

def build_persistent_http(uri, options)
  opts = {:url => uri}
  opts.merge!(options[:connection_adapter_options]) if options[:connection_adapter_options]
  if options[:timeout] && (options[:timeout].is_a?(Integer) || options[:timeout].is_a?(Float))
    opts.merge!(:read_timeout => options[:timeout], :open_timeout => options[:timeout])
  end
  opts.merge!(:debug_output => options[:debug_output]) if options[:debug_output]

  if options[:http_proxyaddr]
    proxy_opts = {:host => options[:http_proxyaddr]}
    proxy_opts[:port] = options[:http_proxyport] if options[:http_proxyport]
    opts[:proxy] = URI::HTTP.build(proxy_opts)
    opts[:proxy].user = options[:http_proxyuser] if options[:http_proxyuser]
    opts[:proxy].password = options[:http_proxypass] if options[:http_proxypass]
  end

  PersistentHTTP.new(opts)
end

#call(uri, options) ⇒ Object



8
9
10
11
12
13
# File 'lib/httparty/persistent/connection_adapter.rb', line 8

def call(uri, options)
  if @persistent_http.nil?
    @persistent_http = build_persistent_http(uri, options)
  end
  @persistent_http
end