Reuse session between requests on a single Faraday::Connection.

This commit is contained in:
Hiten Parmar 2012-02-12 14:56:17 -08:00
parent 1d6e2ace2f
commit b0b1e38607

View File

@ -14,8 +14,7 @@ module Faraday
# TODO: support streaming requests
env[:body] = env[:body].read if env[:body].respond_to? :read
session = ::Patron::Session.new
@block.call(session)
session = @session ||= create_session
if req = env[:request]
session.timeout = session.connect_timeout = req[:timeout] if req[:timeout]
@ -44,6 +43,12 @@ module Faraday
actions << :options unless actions.include? :options
end
end
def create_session
session = ::Patron::Session.new
@block.call(session)
session
end
end
end
end