[前][次][番号順一覧][スレッド一覧]

ruby-changes:14464

From: naruse <ko1@a...>
Date: Tue, 12 Jan 2010 14:57:15 +0900 (JST)
Subject: [ruby-changes:14464] Ruby:r26297 (trunk): * lib/net/http.rb (Net::HTTP#start): add hash argument to

naruse	2010-01-12 14:56:28 +0900 (Tue, 12 Jan 2010)

  New Revision: 26297

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26297

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26296)
+++ ChangeLog	(revision 26297)
@@ -1,3 +1,9 @@
+Tue Jan 12 14:07:31 2010  NARUSE, Yui  <naruse@r...>
+
+	* 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@r...>
 
 	* win32/win32.c (init_env): use _wputenv() instead of
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 26296)
+++ lib/net/http.rb	(revision 26297)
@@ -444,14 +444,44 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]