Class: Faraday::Adapter::HTTPX
- Inherits:
-
Faraday::Adapter
- Object
- Faraday::Adapter
- Faraday::Adapter::HTTPX
- Includes:
- RequestMixin
- Defined in:
- lib/httpx/adapters/faraday.rb
Defined Under Namespace
Modules: RequestMixin Classes: ParallelManager, Session
Constant Summary collapse
- SSL_ERROR =
:nocov:
if defined?(Faraday::SSLError) Faraday::SSLError else Faraday::Error::SSLError end
- CONNECTION_FAILED_ERROR =
if defined?(Faraday::ConnectionFailed) Faraday::ConnectionFailed else Faraday::Error::ConnectionFailed end
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ HTTPX
constructor
A new instance of HTTPX.
Constructor Details
Class Method Details
.setup_parallel_manager ⇒ Object
170 171 172 |
# File 'lib/httpx/adapters/faraday.rb', line 170 def setup_parallel_manager ParallelManager.new end |
Instance Method Details
#call(env) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/httpx/adapters/faraday.rb', line 180 def call(env) super if parallel?(env) handler = env[:parallel_manager].enqueue(env) handler.on_response do |response| save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| response_headers.merge!(response.headers) end end return handler end meth, uri, = build_request(env) session = @session.with((env)) session = session.plugin(:proxy).with(proxy: ) if env.request.proxy response = session.__send__(meth, uri, **) response.raise_for_status unless response.is_a?(::HTTPX::Response) save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers| response_headers.merge!(response.headers) end @app.call(env) rescue OpenSSL::SSL::SSLError => e raise SSL_ERROR, e rescue Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EINVAL, Errno::ENETUNREACH, Errno::EPIPE => e raise CONNECTION_FAILED_ERROR, e end |