diff --git a/lib/faraday/builder.rb b/lib/faraday/builder.rb index 1b98f388..2798d80b 100644 --- a/lib/faraday/builder.rb +++ b/lib/faraday/builder.rb @@ -73,6 +73,17 @@ module Faraday self.class.new(@handlers.dup) end + def app + @app ||= begin + lock! + to_app(lambda { |env| + response = Response.new + response.finish(env) unless env.parallel? + env.response = response + }) + end + end + def to_app(inner_app) # last added handler is the deepest and thus closest to the inner app @handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) } diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 4196e779..9b071ad7 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -100,26 +100,7 @@ module Faraday extend Forwardable - def_delegators :builder, :build, :use, :request, :response, :adapter - - # The "rack app" wrapped in middleware. All requests are sent here. - # - # The builder is responsible for creating the app object. After this, - # the builder gets locked to ensure no further modifications are made - # to the middleware stack. - # - # Returns an object that responds to `call` and returns a Response. - def app - @app ||= begin - builder.lock! - builder.to_app(lambda { |env| - # the inner app that creates and returns the Response object - response = Response.new - response.finish(env) unless env.parallel? - env.response = response - }) - end - end + def_delegators :builder, :build, :use, :request, :response, :adapter, :app # Public: Makes an HTTP request without a body. #