webserver-base 0.5.1

A Rust library which contains shared logic for all of my webserver projects.
Documentation
//! Outbound-call metrics for the relays: the shared `http_client_*` recorder
//! when the `webserver` feature (which owns the metrics recorder) is on, a
//! no-op otherwise.

#[cfg(feature = "webserver")]
pub(super) use crate::webserver::OutboundCall;

/// With no metrics recorder compiled in there is nothing to record to.
#[cfg(not(feature = "webserver"))]
pub(super) struct OutboundCall;

#[cfg(not(feature = "webserver"))]
impl OutboundCall {
    pub(super) const fn start(_target: &'static str, _route: &'static str) -> Self {
        Self
    }

    pub(super) const fn request_bytes(self, _bytes: u64) -> Self {
        self
    }

    pub(super) const fn finish(self, _status: Option<u16>, _response_bytes: Option<u64>) {}
}

impl OutboundCall {
    /// Records the call from a `reqwest` outcome. The response size is the
    /// `Content-Length` header (unknown for a streamed body), because the relays
    /// do not read the bodies they discard.
    pub(super) fn finish_with(self, outcome: &reqwest::Result<reqwest::Response>) {
        match outcome {
            Ok(response) => {
                self.finish(Some(response.status().as_u16()), response.content_length());
            }
            Err(_) => self.finish(None, None),
        }
    }
}