@@ -571,7 +571,7 @@ def HTTP.socket_type #:nodoc: obsolete
571
571
# _opt_ :: optional hash
572
572
#
573
573
# _opt_ sets following values by its accessor.
574
- # The keys are ca_file, ca_path, cert, cert_store, ciphers,
574
+ # The keys are ipaddr, ca_file, ca_path, cert, cert_store, ciphers,
575
575
# close_on_empty_response, key, open_timeout, read_timeout, write_timeout, ssl_timeout,
576
576
# ssl_version, use_ssl, verify_callback, verify_depth and verify_mode.
577
577
# If you set :use_ssl as true, you can use https and default value of
@@ -590,6 +590,7 @@ def HTTP.start(address, *arg, &block) # :yield: +http+
590
590
p_addr = :ENV if arg . size < 2
591
591
port = https_default_port if !port && opt && opt [ :use_ssl ]
592
592
http = new ( address , port , p_addr , p_port , p_user , p_pass )
593
+ http . ipaddr = opt [ :ipaddr ] if opt [ :ipaddr ]
593
594
594
595
if opt
595
596
if opt [ :use_ssl ]
@@ -660,6 +661,7 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p
660
661
def initialize ( address , port = nil )
661
662
@address = address
662
663
@port = ( port || HTTP . default_port )
664
+ @ipaddr = nil
663
665
@local_host = nil
664
666
@local_port = nil
665
667
@curr_http_version = HTTPVersion
@@ -727,6 +729,17 @@ def set_debug_output(output)
727
729
attr_writer :proxy_user
728
730
attr_writer :proxy_pass
729
731
732
+ # The IP address to connect to/used to connect to
733
+ def ipaddr
734
+ started? ? @socket . io . peeraddr [ 3 ] : @ipaddr
735
+ end
736
+
737
+ # Set the IP address to connect to
738
+ def ipaddr = ( addr )
739
+ raise IOError , "ipaddr value changed, but session already started" if started?
740
+ @ipaddr = addr
741
+ end
742
+
730
743
# Number of seconds to wait for the connection to open. Any number
731
744
# may be used, including Floats for fractional seconds. If the HTTP
732
745
# object cannot open a connection in this many seconds, it raises a
@@ -934,20 +947,20 @@ def do_start
934
947
935
948
def connect
936
949
if proxy? then
937
- conn_address = proxy_address
950
+ conn_addr = proxy_address
938
951
conn_port = proxy_port
939
952
else
940
- conn_address = address
953
+ conn_addr = conn_address
941
954
conn_port = port
942
955
end
943
956
944
- D "opening connection to #{ conn_address } :#{ conn_port } ..."
957
+ D "opening connection to #{ conn_addr } :#{ conn_port } ..."
945
958
s = Timeout . timeout ( @open_timeout , Net ::OpenTimeout ) {
946
959
begin
947
- TCPSocket . open ( conn_address , conn_port , @local_host , @local_port )
960
+ TCPSocket . open ( conn_addr , conn_port , @local_host , @local_port )
948
961
rescue => e
949
962
raise e , "Failed to open TCP connection to " +
950
- "#{ conn_address } :#{ conn_port } (#{ e . message } )"
963
+ "#{ conn_addr } :#{ conn_port } (#{ e . message } )"
951
964
end
952
965
}
953
966
s . setsockopt ( Socket ::IPPROTO_TCP , Socket ::TCP_NODELAY , 1 )
@@ -984,7 +997,7 @@ def connect
984
997
OpenSSL ::SSL ::SSLContext ::SESSION_CACHE_CLIENT |
985
998
OpenSSL ::SSL ::SSLContext ::SESSION_CACHE_NO_INTERNAL_STORE
986
999
@ssl_context . session_new_cb = proc { |sock , sess | @ssl_session = sess }
987
- D "starting SSL for #{ conn_address } :#{ conn_port } ..."
1000
+ D "starting SSL for #{ conn_addr } :#{ conn_port } ..."
988
1001
s = OpenSSL ::SSL ::SSLSocket . new ( s , @ssl_context )
989
1002
s . sync_close = true
990
1003
# Server Name Indication (SNI) RFC 3546
@@ -1161,7 +1174,7 @@ def proxy_pass
1161
1174
# without proxy, obsolete
1162
1175
1163
1176
def conn_address # :nodoc:
1164
- address ( )
1177
+ @ipaddr || address ( )
1165
1178
end
1166
1179
1167
1180
def conn_port # :nodoc:
0 commit comments