Class: Falcon::Body::RequestFinished

Inherits:
Protocol::HTTP::Body::Wrapper
  • Object
show all
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. Use this so requests_active stays elevated until the request is fully finished (including response_finished callbacks).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, metric) ⇒ RequestFinished

Returns a new instance of RequestFinished.



34
35
36
37
38
# File 'lib/falcon/body/request_finished.rb', line 34

def initialize(body, metric)
  super(body)
  
  @metric = metric
end

Class Method Details

.wrap(message, metric) ⇒ Object

Wrap a response body with a metric. If the body is nil or empty, decrements immediately.



22
23
24
25
26
27
28
29
30
# File 'lib/falcon/body/request_finished.rb', line 22

def self.wrap(message, metric)
  if body = message&.body and !body.empty?
    message.body = new(body, metric)
  else
    metric.decrement
  end
  
  message
end

Instance Method Details

#close(error = nil) ⇒ Object

Closes the underlying body (invoking rack.response_finished), then decrements the metric.



53
54
55
56
57
58
# File 'lib/falcon/body/request_finished.rb', line 53

def close(error = nil)
  super
  
  @metric&.decrement
  @metric = nil
end

#rewindObject



46
47
48
# File 'lib/falcon/body/request_finished.rb', line 46

def rewind
  false
end

#rewindable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/falcon/body/request_finished.rb', line 41

def rewindable?
  false
end