Skip to content

Commit

Permalink
fix(prometheus): use correct content-type header (#839)
Browse files Browse the repository at this point in the history
* fix(prometheus): use correct content-type header

* test

* fmt?
  • Loading branch information
SimenB authored Jul 9, 2024
1 parent e2f3c58 commit c66d78a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion poem/src/endpoint/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,26 @@ impl Endpoint for PrometheusExporterEndpoint {
let metric_families = self.registry.gather();
let mut result = Vec::new();
match encoder.encode(&metric_families, &mut result) {
Ok(()) => Ok(Response::builder().content_type("text/plain").body(result)),
Ok(()) => Ok(Response::builder()
.content_type(encoder.format_type())
.body(result)),
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR.into()),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::test::TestClient;

#[tokio::test]
async fn test_content_type() {
let client = TestClient::new(PrometheusExporter::new(Registry::new()));

let resp = client.get("/metrics").send().await;

resp.assert_status_is_ok();
resp.assert_content_type("text/plain; version=0.0.4");
}
}

0 comments on commit c66d78a

Please sign in to comment.