lib/httpx/adapters/faraday.rb in httpx-0.19.5 vs lib/httpx/adapters/faraday.rb in httpx-0.19.6
- old
+ new
@@ -97,39 +97,37 @@
@on_data.call(chunk, chunk.bytesize)
end
end
end
- class Session < ::HTTPX::Session
- plugin(:compression)
- plugin(:persistent)
-
- module ReasonPlugin
+ module ReasonPlugin
+ if RUBY_VERSION < "2.5"
+ def self.load_dependencies(*)
+ require "webrick"
+ end
+ else
+ def self.load_dependencies(*)
+ require "net/http/status"
+ end
+ end
+ module ResponseMethods
if RUBY_VERSION < "2.5"
- def self.load_dependencies(*)
- require "webrick"
+ def reason
+ WEBrick::HTTPStatus::StatusMessage.fetch(@status)
end
else
- def self.load_dependencies(*)
- require "net/http/status"
+ def reason
+ Net::HTTP::STATUS_CODES.fetch(@status)
end
end
- module ResponseMethods
- if RUBY_VERSION < "2.5"
- def reason
- WEBrick::HTTPStatus::StatusMessage.fetch(@status)
- end
- else
- def reason
- Net::HTTP::STATUS_CODES.fetch(@status)
- end
- end
- end
end
- plugin(ReasonPlugin)
end
+ def self.session
+ @session ||= ::HTTPX.plugin(:compression).plugin(:persistent).plugin(ReasonPlugin)
+ end
+
class ParallelManager
class ResponseHandler < SimpleDelegator
attr_reader :env
def initialize(env)
@@ -159,11 +157,10 @@
end
include RequestMixin
def initialize
- @session = Session.new
@handlers = []
end
def enqueue(request)
handler = ResponseHandler.new(request)
@@ -172,11 +169,11 @@
end
def run
env = @handlers.last.env
- session = @session.with(options_from_env(env))
+ session = HTTPX.session.with(options_from_env(env))
session = session.plugin(:proxy).with(proxy: { uri: env.request.proxy }) if env.request.proxy
session = session.plugin(OnDataPlugin) if env.request.stream_response?
requests = @handlers.map { |handler| session.build_request(*build_request(handler.env)) }
@@ -203,11 +200,11 @@
end
end
def initialize(app, options = {})
super(app)
- @session = Session.new(options)
+ @session_options = options
end
def call(env)
super
if parallel?(env)
@@ -219,10 +216,12 @@
end
end
return handler
end
- session = @session.with(options_from_env(env))
+ session = HTTPX.session
+ session = session.with(@session_options) unless @session_options.empty?
+ session = session.with(options_from_env(env))
session = session.plugin(:proxy).with(proxy: { uri: env.request.proxy }) if env.request.proxy
session = session.plugin(OnDataPlugin) if env.request.stream_response?
request = session.build_request(*build_request(env))