[#44289] [Ruby 1.9 - Feature #5128][Open] 日本語ドキュメントをUTF-8に — Shyouhei Urabe <shyouhei@...>

34 messages 2011/08/01
[#44293] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Nobuyoshi Nakada <nobu@...> 2011/08/01

[#44295] Re: [ruby-dev:44293] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Urabe Shyouhei <shyouhei@...> 2011/08/01

(08/01/2011 11:52 AM), Nobuyoshi Nakada wrote:

[#44299] Re: [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Nobuyoshi Nakada <nobu@...> 2011/08/01

なかだです。

[#44418] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Ayumu AIZAWA <ayumu.aizawa@...> 2011/08/24

[#44431] Re: [ruby-dev:44418] [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — KOSAKI Motohiro <kosaki.motohiro@...> 2011/08/27

> あいざわです

[#44443] Re: [Ruby 1.9 - Feature #5128] 日本語ドキュメントをUTF-8に — Ayumu Aizawa <ayumu.aizawa@...> 2011/09/01

あいざわです

[#44315] [Ruby 1.9 - Bug #5139][Open] sigsegv のスタックオーバフロー — Tomoyuki Chikanaga <nagachika00@...>

18 messages 2011/08/02

[#44329] [Ruby 1.9 - Bug #5151][Open] test/socket/test_socket.rb fail when udp connection failed — Ayumu AIZAWA <ayumu.aizawa@...>

16 messages 2011/08/02

[#44368] [Ruby 1.9 - Feature #5180][Open] net/http の接続時に用いる IP アドレスの指定 — Yui NARUSE <naruse@...>

15 messages 2011/08/10

[#44413] [Ruby 1.9 - Bug #5217][Open] lineno is broken when source code has about 7000 lines — Yusuke Endoh <mame@...>

11 messages 2011/08/23

[ruby-dev:44368] [Ruby 1.9 - Feature #5180][Open] net/http の接続時に用いる IP アドレスの指定

From: Yui NARUSE <naruse@...>
Date: 2011-08-10 02:46:20 UTC
List: ruby-dev #44368
Issue #5180 has been reported by Yui NARUSE.

----------------------------------------
Feature #5180: net/http の接続時に用いる IP アドレスの指定
http://redmine.ruby-lang.org/issues/5180

Author: Yui NARUSE
Status: Open
Priority: Normal
Assignee: 
Category: lib
Target version: 


通常 net/http を使う時は、Net::HTTP.start("ruby-lang.org") などとホスト名を使います。
で、Socket がホスト名から IP アドレスを引いて、コネクションが張られます。
普通の人はこれで足りるわけですが、ふつうな人はしばしば DNS で引けない IP アドレスに接続したくなります。
例えば、ホスト名は "ruby-lang.org" としたいが、IP アドレスは 127.0.0.1 とか。

以下のパッチをあてると、
Net::HTTP.start("ruby-lang.org", ipaddr: '127.0.0.1')
などとできるようになります。

diff --git a/lib/net/http.rb b/lib/net/http.rb
index 7b9ec4f..6d034e0 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -524,7 +524,7 @@ module Net   #:nodoc:
     # _opt_     :: optional hash
     #
     # _opt_ sets following values by its accessor.
-    # The keys are ca_file, ca_path, cert, cert_store, ciphers,
+    # The keys are ipaddr, 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
@@ -542,6 +542,7 @@ module Net   #:nodoc:
       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)
+      http.ipaddr = opt[:ipaddr] if opt[:ipaddr]
 
       if opt
         if opt[:use_ssl]
@@ -575,6 +576,7 @@ module Net   #:nodoc:
     def initialize(address, port = nil)
       @address = address
       @port    = (port || HTTP.default_port)
+      @ipaddr = nil
       @curr_http_version = HTTPVersion
       @no_keepalive_server = false
       @close_on_empty_response = false
@@ -620,6 +622,17 @@ module Net   #:nodoc:
     # The port number to connect to.
     attr_reader :port
 
+    # The IP address to connect to/used to connect to
+    def ipaddr
+      started? ?  @socket.io.peeraddr[3] : @ipaddr
+    end
+
+    # Set the IP address to connect to
+    def ipaddr=(addr)
+      raise IOError, "ipaddr value changed, but session already started" if started?
+      @ipaddr = addr
+    end
+
     # Number of seconds to wait for the connection to open. Any number
     # may be used, including Floats for fractional seconds. If the HTTP
     # object cannot open a connection in this many seconds, it raises a
@@ -945,7 +958,7 @@ module Net   #:nodoc:
     # without proxy
 
     def conn_address
-      address()
+      @ipaddr || address()
     end
 
     def conn_port


-- 
http://redmine.ruby-lang.org

In This Thread

Prev Next