* lib/net/http.rb (Net::HTTP#start): add hash argument to

set ssl related options. when use_ssl is set default value
  of verify_mode is OpenSSL::SSL::VERIFY_PEER. [ruby-dev:40003]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-01-12 05:56:28 +00:00
Родитель 4301bbbe0f
Коммит b5227ae183
2 изменённых файлов: 39 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Tue Jan 12 14:07:31 2010 NARUSE, Yui <naruse@ruby-lang.org>
* lib/net/http.rb (Net::HTTP#start): add hash argument to
set ssl related options. when use_ssl is set default value
of verify_mode is OpenSSL::SSL::VERIFY_PEER. [ruby-dev:40003]
Tue Jan 12 14:53:07 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (init_env): use _wputenv() instead of

Просмотреть файл

@ -444,14 +444,44 @@ module Net #:nodoc:
end
# creates a new Net::HTTP object and opens its TCP connection and
# HTTP session. If the optional block is given, the newly
# 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.
def HTTP.start(address, port = nil, p_addr = nil, p_port = nil, p_user = nil, p_pass = nil, &block) # :yield: +http+
new(address, port, p_addr, p_port, p_user, p_pass).start(&block)
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 opt[:use_ssl] && !port
http = new(address, port, p_addr, p_port, p_user, p_pass)
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
http.start(&block)
end
class << HTTP