Class: Falcon::Body::RequestFinished
- Inherits:
-
Protocol::HTTP::Body::Wrapper
- Object
- Protocol::HTTP::Body::Wrapper
- Falcon::Body::RequestFinished
- Defined in:
- lib/falcon/body/request_finished.rb
Overview
Wraps a response body and decrements a metric after the body is closed.
Runs close on the underlying body first (which invokes rack.response_finished), then decrements the metric, even if closing raises. Use this so requests_active stays elevated until the request is fully finished (including response_finished callbacks), without leaking if close reports an error.
Class Method Summary collapse
-
.wrap(message, metric) ⇒ Object
Wrap a response body with a metric.
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
Closes the underlying body (invoking rack.response_finished), then decrements the metric.
-
#initialize(body, metric) ⇒ RequestFinished
constructor
Initialize the wrapper.
- #rewind ⇒ Object
- #rewindable? ⇒ Boolean
Constructor Details
#initialize(body, metric) ⇒ RequestFinished
Initialize the wrapper.
39 40 41 42 43 |
# File 'lib/falcon/body/request_finished.rb', line 39 def initialize(body, metric) super(body) @metric = metric end |
Class Method Details
.wrap(message, metric) ⇒ Object
Wrap a response body with a metric.
Expects the caller to have incremented ‘requests_active` beforehand. If the body is not wrapped (nil or empty message/body, or an error while assigning the wrapper), the `ensure` block decrements once. When wrapped, the metric is decremented in #close.
25 26 27 28 29 30 31 32 33 |
# File 'lib/falcon/body/request_finished.rb', line 25 def self.wrap(, metric) if body = &.body and !body.empty? .body = new(body, metric) else metric.decrement end end |
Instance Method Details
#close(error = nil) ⇒ Object
Closes the underlying body (invoking rack.response_finished), then decrements the metric.
58 59 60 61 62 63 |
# File 'lib/falcon/body/request_finished.rb', line 58 def close(error = nil) super ensure @metric&.decrement @metric = nil end |
#rewind ⇒ Object
51 52 53 |
# File 'lib/falcon/body/request_finished.rb', line 51 def rewind false end |
#rewindable? ⇒ Boolean
46 47 48 |
# File 'lib/falcon/body/request_finished.rb', line 46 def rewindable? false end |