servlet 1.1.0

A small application runtime with an explicit operational contract
Documentation
//! Registration makes client cleanup part of the existing lifecycle coordinator.
use super::{ClientConfig, ClientError, Request, state::Inner};
use std::sync::Arc;

/// A reusable named client restricted to one explicitly configured origin.
#[derive(Clone)]
pub struct Client(pub(super) Arc<Inner>);
impl Client {
    /// Prepare a request to an absolute path in the approved origin. Query values
    /// are permitted but never included in Servlet's error messages. Only GET, HEAD,
    /// POST, PUT, PATCH, DELETE, and OPTIONS methods are supported.
    pub fn request(&self, method: reqwest::Method, path: &str) -> Result<Request, ClientError> {
        Request::new(self.0.clone(), method, path)
    }
    /// Prepare a GET to an absolute path in the approved origin.
    pub fn get(&self, path: &str) -> Result<Request, ClientError> {
        self.request(reqwest::Method::GET, path)
    }
    /// Clone the native transport without configured credential headers.
    ///
    /// This explicit escape hatch bypasses managed destination, capacity, total
    /// inherited deadline, and body bounds. The caller owns its work and lifetime;
    /// it can outlive managed cleanup. Native transport defaults still apply.
    pub fn raw(&self) -> Result<reqwest::Client, ClientError> {
        self.0.raw()
    }
    /// Reject new managed work, cancel polled exchanges, and wait for every lease.
    /// An unpolled retained body holds its lease until polled or dropped. Managed
    /// cleanup applies the coordinator's remaining shutdown budget to this wait.
    pub async fn close(&self) {
        self.0.close().await;
    }
}
impl crate::setup::SetupContext {
    /// Register a named HTTP client without contacting its destination. Cleanup
    /// runs after accepted work and application cleanup. A retained unpolled body
    /// may cause a reported cleanup timeout. There is no implicit readiness check;
    /// register a bounded cached check explicitly if this dependency is critical.
    ///
    /// The resource name is a metric label and span field: choose a stable, non-secret
    /// name up to 128 bytes. Six metric definitions and 38 fixed series share the
    /// app registry's budget; registration failure remains a setup error.
    pub fn http_client(
        &mut self,
        name: impl Into<String>,
        config: ClientConfig,
    ) -> Result<Client, ClientError> {
        let name = name.into();
        if name.trim().is_empty() || name.len() > 128 {
            return Err(ClientError::Registration);
        }
        let metrics = super::metrics::Measurements::new(&name)?;
        let transport = config.build()?;
        let client = Client(Inner::new(
            config,
            transport,
            name.clone().into(),
            metrics.clone(),
        ));
        let owner = client.clone();
        self.cleanup(name, move || async move {
            owner.close().await;
            Ok(())
        })
        .map_err(|_| ClientError::Registration)?;
        metrics.register(&self.metrics())?;
        Ok(client)
    }
}