mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-03 00:02:48 -04:00
31 lines
641 B
Ruby
31 lines
641 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Faraday
|
|
# Middleware is the basic base class of any Faraday middleware.
|
|
class Middleware
|
|
extend MiddlewareRegistry
|
|
|
|
attr_reader :app, :options
|
|
|
|
def initialize(app = nil, options = {})
|
|
@app = app
|
|
@options = options
|
|
end
|
|
|
|
def call(env)
|
|
on_request(env) if respond_to?(:on_request)
|
|
app.call(env).on_complete do |environment|
|
|
on_complete(environment) if respond_to?(:on_complete)
|
|
end
|
|
end
|
|
|
|
def close
|
|
if app.respond_to?(:close)
|
|
app.close
|
|
else
|
|
warn "#{app} does not implement \#close!"
|
|
end
|
|
end
|
|
end
|
|
end
|