mirror of
https://github.com/lostisland/faraday.git
synced 2025-11-20 00:01:57 -05:00
Move #app from Connection to Builder
This commit is contained in:
parent
64892e2e9c
commit
d10c01f111
@ -73,6 +73,17 @@ module Faraday
|
|||||||
self.class.new(@handlers.dup)
|
self.class.new(@handlers.dup)
|
||||||
end
|
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)
|
def to_app(inner_app)
|
||||||
# last added handler is the deepest and thus closest to the 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) }
|
@handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) }
|
||||||
|
|||||||
@ -100,26 +100,7 @@ module Faraday
|
|||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
def_delegators :builder, :build, :use, :request, :response, :adapter
|
def_delegators :builder, :build, :use, :request, :response, :adapter, :app
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Public: Makes an HTTP request without a body.
|
# Public: Makes an HTTP request without a body.
|
||||||
#
|
#
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user