Permalink
Browse files

Adding local_sockaddr

  • Loading branch information...
1 parent 7851974 commit 02975550927df2045b7597221f3bd3728057aa23 @icblenke icblenke committed with Nov 3, 2009
Showing with 15 additions and 0 deletions.
  1. +3 −0 lib/httpclient.rb
  2. +12 −0 lib/httpclient/session.rb
View
3 lib/httpclient.rb
@@ -330,6 +330,8 @@ def attr_proxy(symbol, assignable = false)
attr_proxy(:test_loopback_http_response)
# Decompress a compressed (with gzip or deflate) content body transparently. false by default.
attr_proxy(:transparent_gzip_decompression, true)
+ # Local IP Address to bind() local side of the socket to
+ attr_proxy(:local_sockaddr,true)
# Default extheader for PROPFIND request.
PROPFIND_DEFAULT_EXTHEADER = { 'Depth' => '0' }
@@ -366,6 +368,7 @@ def initialize(*args)
@session_manager.ssl_config = @ssl_config = SSLConfig.new(self)
@cookie_manager = WebAgent::CookieManager.new
@follow_redirect_count = 10
+ @local_sockaddr = nil
load_environment
self.proxy = proxy if proxy
end
View
12 lib/httpclient/session.rb
@@ -103,6 +103,9 @@ class SessionManager
attr_accessor :read_block_size
attr_accessor :protocol_retry_count
+ # Local sockaddr structure to bind() to before connect
+ attr_accessor :local_sockaddr
+
attr_accessor :ssl_config
attr_reader :test_loopback_http_response
@@ -132,6 +135,8 @@ def initialize(client)
@test_loopback_http_response = []
@transparent_gzip_decompression = false
+ @local_sockaddr = nil
+
@sess_pool = []
@sess_pool_mutex = Mutex.new
end
@@ -198,6 +203,7 @@ def open(uri, via_proxy = false)
sess.protocol_retry_count = @protocol_retry_count
sess.ssl_config = @ssl_config
sess.debug_dev = @debug_dev
+ sess.local_sockaddr = @local_sockaddr
sess.test_loopback_http_response = @test_loopback_http_response
sess.transparent_gzip_decompression = @transparent_gzip_decompression
end
@@ -508,6 +514,9 @@ class Session
attr_accessor :read_block_size
attr_accessor :protocol_retry_count
+ # Local sockaddr to bind() to for connect
+ attr_accessor :local_sockaddr
+
attr_accessor :ssl_config
attr_reader :ssl_peer_cert
attr_accessor :test_loopback_http_response
@@ -536,6 +545,8 @@ def initialize(client, dest, agent_name, from)
@test_loopback_http_response = nil
+ @local_sockaddr = nil
+
@agent_name = agent_name
@from = from
@state = :INIT
@@ -692,6 +703,7 @@ def connect
begin
timeout(@connect_timeout, ConnectTimeoutError) do
@socket = create_socket(site)
+ @socket.bind = @local_sockaddr if @local_sockaddr
if https?(@dest)
if @socket.is_a?(LoopBackSocket)
connect_ssl_proxy(@socket, URI.parse(@dest.to_s)) if @proxy

0 comments on commit 0297555

Please sign in to comment.