Skip to content
This repository
Browse code

Adding local_sockaddr

  • Loading branch information...
commit 02975550927df2045b7597221f3bd3728057aa23 1 parent 7851974
Ian Blenke icblenke authored committed

Showing 2 changed files with 15 additions and 0 deletions. Show diff stats Hide diff stats

  1. +3 0  lib/httpclient.rb
  2. +12 0 lib/httpclient/session.rb
3  lib/httpclient.rb
@@ -330,6 +330,8 @@ def attr_proxy(symbol, assignable = false)
330 330 attr_proxy(:test_loopback_http_response)
331 331 # Decompress a compressed (with gzip or deflate) content body transparently. false by default.
332 332 attr_proxy(:transparent_gzip_decompression, true)
  333 + # Local IP Address to bind() local side of the socket to
  334 + attr_proxy(:local_sockaddr,true)
333 335
334 336 # Default extheader for PROPFIND request.
335 337 PROPFIND_DEFAULT_EXTHEADER = { 'Depth' => '0' }
@@ -366,6 +368,7 @@ def initialize(*args)
366 368 @session_manager.ssl_config = @ssl_config = SSLConfig.new(self)
367 369 @cookie_manager = WebAgent::CookieManager.new
368 370 @follow_redirect_count = 10
  371 + @local_sockaddr = nil
369 372 load_environment
370 373 self.proxy = proxy if proxy
371 374 end
12 lib/httpclient/session.rb
@@ -103,6 +103,9 @@ class SessionManager
103 103 attr_accessor :read_block_size
104 104 attr_accessor :protocol_retry_count
105 105
  106 + # Local sockaddr structure to bind() to before connect
  107 + attr_accessor :local_sockaddr
  108 +
106 109 attr_accessor :ssl_config
107 110
108 111 attr_reader :test_loopback_http_response
@@ -132,6 +135,8 @@ def initialize(client)
132 135 @test_loopback_http_response = []
133 136
134 137 @transparent_gzip_decompression = false
  138 + @local_sockaddr = nil
  139 +
135 140 @sess_pool = []
136 141 @sess_pool_mutex = Mutex.new
137 142 end
@@ -198,6 +203,7 @@ def open(uri, via_proxy = false)
198 203 sess.protocol_retry_count = @protocol_retry_count
199 204 sess.ssl_config = @ssl_config
200 205 sess.debug_dev = @debug_dev
  206 + sess.local_sockaddr = @local_sockaddr
201 207 sess.test_loopback_http_response = @test_loopback_http_response
202 208 sess.transparent_gzip_decompression = @transparent_gzip_decompression
203 209 end
@@ -508,6 +514,9 @@ class Session
508 514 attr_accessor :read_block_size
509 515 attr_accessor :protocol_retry_count
510 516
  517 + # Local sockaddr to bind() to for connect
  518 + attr_accessor :local_sockaddr
  519 +
511 520 attr_accessor :ssl_config
512 521 attr_reader :ssl_peer_cert
513 522 attr_accessor :test_loopback_http_response
@@ -536,6 +545,8 @@ def initialize(client, dest, agent_name, from)
536 545
537 546 @test_loopback_http_response = nil
538 547
  548 + @local_sockaddr = nil
  549 +
539 550 @agent_name = agent_name
540 551 @from = from
541 552 @state = :INIT
@@ -692,6 +703,7 @@ def connect
692 703 begin
693 704 timeout(@connect_timeout, ConnectTimeoutError) do
694 705 @socket = create_socket(site)
  706 + @socket.bind = @local_sockaddr if @local_sockaddr
695 707 if https?(@dest)
696 708 if @socket.is_a?(LoopBackSocket)
697 709 connect_ssl_proxy(@socket, URI.parse(@dest.to_s)) if @proxy

0 comments on commit 0297555

Please sign in to comment.
Something went wrong with that request. Please try again.