Class: Rack::ExpectationCascade
- Inherits:
-
Object
- Object
- Rack::ExpectationCascade
- Defined in:
- lib/rack/contrib/expectation_cascade.rb
Constant Summary collapse
- Expect =
"Expect".freeze
- ContinueExpectation =
"100-continue".freeze
- ExpectationFailed =
[417, {"Content-Type" => "text/html"}, []].freeze
- NotFound =
[404, {"Content-Type" => "text/html"}, []].freeze
Instance Attribute Summary collapse
-
#apps ⇒ Object
readonly
Returns the value of attribute apps.
Instance Method Summary collapse
- #<<(app) ⇒ Object
- #call(env) ⇒ Object
-
#initialize {|_self| ... } ⇒ ExpectationCascade
constructor
A new instance of ExpectationCascade.
Constructor Details
#initialize {|_self| ... } ⇒ ExpectationCascade
Returns a new instance of ExpectationCascade.
11 12 13 14 |
# File 'lib/rack/contrib/expectation_cascade.rb', line 11 def initialize @apps = [] yield self if block_given? end |
Instance Attribute Details
#apps ⇒ Object (readonly)
Returns the value of attribute apps.
9 10 11 |
# File 'lib/rack/contrib/expectation_cascade.rb', line 9 def apps @apps end |
Instance Method Details
#<<(app) ⇒ Object
28 29 30 |
# File 'lib/rack/contrib/expectation_cascade.rb', line 28 def <<(app) @apps << app end |
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# 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 |