diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-12 05:56:28 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-12 05:56:28 +0000 |
commit | b5227ae183ca7cf1a32d7daeafc2b7249f656a39 (patch) | |
tree | ab0ffe0204b85b2e448f0b30bbb06186454c924f | |
parent | 4301bbbe0f115b7d7389d0b37e8c8bfcc9b2ab49 (diff) | |
download | ruby-b5227ae183ca7cf1a32d7daeafc2b7249f656a39.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/net/http.rb | 36 |
2 files changed, 39 insertions, 3 deletions
@@ -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 diff --git a/lib/net/http.rb b/lib/net/http.rb index e0d35e598d..31546d3020 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -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 |