///|
/// Select one already-complete body for a framework-neutral metrics response.
///
/// This is intentionally a pure function. A concrete server first calls
/// `negotiate`, gathers and encodes exactly the selected format, then maps an
/// encoder error to `internal_error_response`. Passing both bodies here keeps
/// the content-negotiation contract directly testable without a web runtime.
pub fn negotiated_metrics_response(
accept : String?,
prometheus_body : String,
openmetrics_body : String,
) -> MetricsResponse {
try negotiate(accept) catch {
MalformedAccept(_) | AcceptHeaderTooLarge => bad_request_response()
NotAcceptable => not_acceptable_response()
} noraise {
format =>
match format {
PrometheusText => metrics_response(PrometheusText, prometheus_body)
OpenMetricsText => metrics_response(OpenMetricsText, openmetrics_body)
}
}
}