Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threading: do not memoize/reuse Patron session #796

Merged
merged 1 commit into from
May 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/faraday/adapter/patron.rb
Original file line number Diff line number Diff line change
@@ -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]
@@ -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]
4 changes: 2 additions & 2 deletions test/adapters/integration.rb
Original file line number Diff line number Diff line change
@@ -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

10 changes: 6 additions & 4 deletions test/adapters/patron_test.rb
Original file line number Diff line number Diff line change
@@ -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