Class: HTTP::ClientConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/http_client/jruby/client_configuration.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
30_000

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ClientConfiguration

Returns a new instance of ClientConfiguration.



58
59
60
61
62
63
64
65
# File 'lib/http_client/jruby/client_configuration.rb', line 58

def initialize(options = {})
  self.so_timeout = DEFAULT_TIMEOUT

  options.each do |parameter_name, parameter_value|
    setter_name = "#{parameter_name}="
    self.send(setter_name, parameter_value) if self.respond_to?(setter_name)
  end
end

Instance Method Details

#build_http_clientObject



67
68
69
# File 'lib/http_client/jruby/client_configuration.rb', line 67

def build_http_client
  DefaultHttpClient.new(params)
end

#default_host=(host) ⇒ Object



88
89
90
# File 'lib/http_client/jruby/client_configuration.rb', line 88

def default_host=(host)
  set_host_parameter(HTTP::ClientPNames::DEFAULT_HOST, host)
end

#default_proxy=(host) ⇒ Object



80
81
82
# File 'lib/http_client/jruby/client_configuration.rb', line 80

def default_proxy=(host)
  set_host_parameter(HTTP::ConnRoutePNames::DEFAULT_PROXY, host)
end

#local_address=(local_addr_str) ⇒ Object



76
77
78
# File 'lib/http_client/jruby/client_configuration.rb', line 76

def local_address=(local_addr_str)
  params.set_parameter HTTP::ConnRoutePNames::LOCAL_ADDRESS, java.net.InetAddress.getByName(local_addr_str)
end

#protocol_version=(version_string) ⇒ Object



71
72
73
74
# File 'lib/http_client/jruby/client_configuration.rb', line 71

def protocol_version=(version_string)
  protocol, major_version, minor_version = version_string.split(/[\.|\s|\/]/)
  params.set_parameter HTTP::CoreProtocolPNames::PROTOCOL_VERSION, org.apache.http.ProtocolVersion.new(protocol, major_version.to_i, minor_version.to_i)
end

#timeout_in_seconds=(timeout) ⇒ Object



92
93
94
# File 'lib/http_client/jruby/client_configuration.rb', line 92

def timeout_in_seconds=(timeout)
  self.so_timeout = timeout * 1000
end

#virtual_host=(host) ⇒ Object



84
85
86
# File 'lib/http_client/jruby/client_configuration.rb', line 84

def virtual_host=(host)
  set_host_parameter(HTTP::ClientPNames::VIRTUAL_HOST, host)
end