Class: Faraday::Adapter::Rack
- Inherits:
-
Faraday::Adapter
- Object
- Faraday::Adapter
- Faraday::Adapter::Rack
- Defined in:
- lib/faraday/adapter/rack.rb
Overview
Sends requests to a Rack app.
Constant Summary collapse
- SPECIAL_HEADERS =
not prefixed with “HTTP_”
%w[CONTENT_LENGTH CONTENT_TYPE].freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(faraday_app, rack_app) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(faraday_app, rack_app) ⇒ Rack
Returns a new instance of Rack.
25 26 27 28 29 |
# File 'lib/faraday/adapter/rack.rb', line 25 def initialize(faraday_app, rack_app) super(faraday_app) mock_session = ::Rack::MockSession.new(rack_app) @session = ::Rack::Test::Session.new(mock_session) end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/faraday/adapter/rack.rb', line 31 def call(env) super rack_env = build_rack_env(env) env[:request_headers]&.each do |name, value| name = name.upcase.tr('-', '_') name = "HTTP_#{name}" unless SPECIAL_HEADERS.include? name rack_env[name] = value end timeout = request_timeout(:open, env[:request]) timeout ||= request_timeout(:read, env[:request]) response = if timeout ::Timeout.timeout(timeout, Faraday::TimeoutError) do execute_request(env, rack_env) end else execute_request(env, rack_env) end if (req = env[:request]).stream_response? warn "Streaming downloads for #{self.class.name} " \ 'are not yet implemented.' req.on_data.call(response.body, response.body.bytesize) end save_response(env, response.status, response.body, response.headers) @app.call env end |