Permalink
Browse files

Merge pull request #118 from hrp/master

Add ability to set options for a Patron::Session and reuse Patron::Session for each
  • Loading branch information...
2 parents 3034642 + 7f61f22 commit 9f1181c84665c79978512a8ffd1c9b16a97b4197 @technoweenie committed Apr 14, 2012
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/faraday/adapter/patron.rb
@@ -3,13 +3,18 @@ class Adapter
class Patron < Faraday::Adapter
dependency 'patron'
+ def initialize(app, &block)
+ super(app)
+ @block = block if block_given?
+ end
+
def call(env)
super
# TODO: support streaming requests
env[:body] = env[:body].read if env[:body].respond_to? :read
- session = ::Patron::Session.new
+ session = @session ||= create_session
if req = env[:request]
session.timeout = session.connect_timeout = req[:timeout] if req[:timeout]
@@ -45,6 +50,12 @@ def call(env)
actions << :options unless actions.include? :options
end
end
+
+ def create_session
+ session = ::Patron::Session.new
+ @block.call(session) if @block
+ session
+ end
end
def prepend_proxy_auth_string(proxy, session)

0 comments on commit 9f1181c

Please sign in to comment.