LCOV - code coverage report
Current view: top level - proxy/src/http - health_server.rs (source / functions) Coverage Total Hit
Test: aca8877be6ceba750c1be359ed71bc1799d52b30.info Lines: 86.7 % 15 13
Test Date: 2024-02-14 18:05:35 Functions: 88.9 % 9 8

            Line data    Source code
       1              : use anyhow::{anyhow, bail};
       2              : use hyper::{Body, Request, Response, StatusCode};
       3              : use std::{convert::Infallible, net::TcpListener};
       4              : use tracing::info;
       5              : use utils::http::{endpoint, error::ApiError, json::json_response, RouterBuilder, RouterService};
       6              : 
       7           25 : async fn status_handler(_: Request<Body>) -> Result<Response<Body>, ApiError> {
       8           25 :     json_response(StatusCode::OK, "")
       9           25 : }
      10              : 
      11           25 : fn make_router() -> RouterBuilder<hyper::Body, ApiError> {
      12           25 :     endpoint::make_router().get("/v1/status", status_handler)
      13           25 : }
      14              : 
      15           25 : pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<Infallible> {
      16           25 :     scopeguard::defer! {
      17           25 :         info!("http has shut down");
      18              :     }
      19              : 
      20           25 :     let service = || RouterService::new(make_router().build()?);
      21              : 
      22           25 :     hyper::Server::from_tcp(http_listener)?
      23           25 :         .serve(service().map_err(|e| anyhow!(e))?)
      24           26 :         .await?;
      25              : 
      26            0 :     bail!("hyper server without shutdown handling cannot shutdown successfully");
      27            0 : }
        

Generated by: LCOV version 2.1-beta