Skip to content

Commit

Permalink
Fix: do not memoize/reuse Patron session (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
julik authored and iMacTia committed May 10, 2018
1 parent 5f1687a commit ac66113
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
9 changes: 2 additions & 7 deletions lib/faraday/adapter/patron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def call(env)
# TODO: support streaming requests
env[:body] = env[:body].read if env[:body].respond_to? :read

session = @session ||= create_session
session = ::Patron::Session.new
@config_block.call(session) if @config_block
configure_ssl(session, env[:ssl]) if env[:url].scheme == 'https' and env[:ssl]

if req = env[:request]
Expand Down Expand Up @@ -65,12 +66,6 @@ def call(env)
end
end

def create_session
session = ::Patron::Session.new
@config_block.call(session) if @config_block
session
end

def configure_ssl(session, ssl)
if ssl.fetch(:verify, true)
session.cacert = ssl[:ca_file]
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ def adapter_options
[]
end

def create_connection(options = {})
def create_connection(options = {}, &optional_connection_config_blk)
if adapter == :default
builder_block = nil
else
builder_block = Proc.new do |b|
b.request :multipart
b.request :url_encoded
b.adapter adapter, *adapter_options
b.adapter adapter, *adapter_options, &optional_connection_config_blk
end
end

Expand Down
10 changes: 6 additions & 4 deletions test/adapters/patron_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ def adapter() :patron end
end

def test_custom_adapter_config
adapter = Faraday::Adapter::Patron.new do |session|
conn = create_connection do |session|
assert_kind_of ::Patron::Session, session
session.max_redirects = 10
throw :config_block_called
end

session = adapter.create_session

assert_equal 10, session.max_redirects
assert_throws(:config_block_called) do
conn.get 'http://8.8.8.8:88'
end
end

def test_connection_timeout
Expand Down

0 comments on commit ac66113

Please sign in to comment.