servlet 1.1.0

A small application runtime with an explicit operational contract
Documentation
//! Generated correlation and trusted route templates, never raw URLs or headers.
use super::RequestId;
use axum::{
    extract::{MatchedPath, Request},
    middleware::Next,
    response::Response,
};
use zlid::ZLID;

pub(super) fn request_id() -> zlid::Result<RequestId> {
    ZLID::random().map(|id| RequestId(id.text()))
}

pub(super) fn method(method: &axum::http::Method) -> &'static str {
    match method.as_str() {
        "GET" => "GET",
        "POST" => "POST",
        "PUT" => "PUT",
        "PATCH" => "PATCH",
        "DELETE" => "DELETE",
        "HEAD" => "HEAD",
        "OPTIONS" => "OPTIONS",
        "CONNECT" => "CONNECT",
        "TRACE" => "TRACE",
        "QUERY" => "QUERY",
        _ => "_OTHER",
    }
}
pub(super) async fn route(request: Request, next: Next) -> Response {
    if let Some(path) = request.extensions().get::<MatchedPath>() {
        tracing::Span::current().record("route", path.as_str());
        #[cfg(feature = "otel")]
        {
            use opentelemetry::trace::TraceContextExt;
            use tracing_opentelemetry::OpenTelemetrySpanExt;
            tracing::Span::current().record("http.route", path.as_str());
            let method = match method(request.method()) {
                "_OTHER" => "HTTP",
                method => method,
            };
            // The bridge starts on enter and ignores subsequent otel.name records.
            tracing::Span::current()
                .context()
                .span()
                .update_name(format!("{} {}", method, path.as_str()));
        }
    }
    next.run(request).await
}