class Rack::ExpectationCascade

Constants

ContinueExpectation
Expect
ExpectationFailed
NotFound

Attributes

apps[R]

Public Instance Methods

<<(app) click to toggle source
# File lib/rack/contrib/expectation_cascade.rb, line 28
def <<(app)
  @apps << app
end
call(env) click to toggle source
# File lib/rack/contrib/expectation_cascade.rb, line 16
def call(env)
  set_expectation = env[Expect] != ContinueExpectation
  env[Expect] = ContinueExpectation if set_expectation
  @apps.each do |app|
    result = app.call(env)
    return result unless result[0].to_i == 417
  end
  set_expectation ? NotFound : ExpectationFailed
ensure
  env.delete(Expect) if set_expectation
end

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/rack/contrib/expectation_cascade.rb, line 11
def initialize
  @apps = []
  yield self if block_given?
end