Method: Net::HTTP.start

Defined in:
lib/net/http.rb

.start(address, *arg, &block) ⇒ Object

call-seq:

HTTP.start(address, port, p_addr, p_port, p_user, p_pass, &block)
HTTP.start(address, port=nil, p_addr=nil, p_port=nil, p_user=nil, p_pass=nil, opt, &block)

creates a new Net::HTTP object and opens its TCP connection and HTTP session.

Argments are following:

address

hostname or IP address of the server

port

port of the server

p_addr

address of proxy

p_port

port of proxy

p_user

user of proxy

p_pass

pass of proxy

opt

optional hash

opt sets following values by its accessor. The keys are ca_file, ca_path, cert, cert_store, ciphers, close_on_empty_response, key, open_timeout, read_timeout, ssl_timeout, ssl_version, use_ssl, verify_callback, verify_depth and verify_mode. If you set :use_ssl as true, you can use https and default value of verify_mode is set as OpenSSL::SSL::VERIFY_PEER.

If the optional block is given, the newly created Net::HTTP object is passed to it and closed when the block finishes. In this case, the return value of this method is the return value of the block. If no block is given, the return value of this method is the newly created Net::HTTP object itself, and the caller is responsible for closing it upon completion.



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/net/http.rb', line 475

def HTTP.start(address, *arg, &block) # :yield: +http+
  arg.pop if opt = Hash.try_convert(arg[-1])
  port, p_addr, p_port, p_user, p_pass = *arg
  port = https_default_port if !port && opt && opt[:use_ssl]
  http = new(address, port, p_addr, p_port, p_user, p_pass)

  if opt
    opt = {verify_mode: OpenSSL::SSL::VERIFY_PEER}.update(opt) if opt[:use_ssl]
    http.methods.grep(/\A(\w+)=\z/) do |meth|
      key = $1.to_sym
      opt.key?(key) or next
      http.__send__(meth, opt[key])
    end
  end

  http.start(&block)
end