FalconSourceFalconBodyRequestFinished

class RequestFinished

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).

Definitions

def self.wrap(message, metric)

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

Signature

parameter message Protocol::HTTP::Response

The response whose body to wrap.

parameter metric Async::Utilization::Metric

The metric to decrement when the body is closed.

returns Protocol::HTTP::Response

The message (modified in place).

Implementation

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

def initialize(body, metric)

Signature

parameter body Protocol::HTTP::Body::Readable

The body to wrap.

parameter metric Async::Utilization::Metric

The metric to decrement on close.

Implementation

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

def rewindable?

Signature

returns Boolean

False, the wrapper does not support rewinding.

Implementation

def rewindable?
	false
end

def rewind

Signature

returns Boolean

False, rewinding is not supported.

Implementation

def rewind
	false
end

def close(error = nil)

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

Signature

parameter error Exception, nil

Optional error that caused the close.

Implementation

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