servlet 1.0.0

A small application runtime with an explicit operational contract
Documentation
//! Safe runtime failures and server-generated correlation identifiers.

use axum::{
    Json,
    http::{StatusCode, header},
    response::{IntoResponse, Response},
};
use serde::Serialize;

/// Server-generated identifier, available as an Axum request extension.
/// Incoming request IDs and forwarding headers never influence this value.
#[derive(Clone, Debug)]
pub struct RequestId(pub String);

/// RFC 9457 problem details for failures generated by Servlet.
#[derive(Clone, Debug, Serialize)]
pub struct Problem {
    /// A stable problem type URI.
    #[serde(rename = "type")]
    pub kind: &'static str,
    /// A fixed, safe summary.
    pub title: &'static str,
    /// HTTP status code.
    pub status: u16,
    /// Stable machine-readable failure code.
    pub code: &'static str,
    /// Correlation with the response header and local telemetry.
    pub request_id: String,
}

impl Problem {
    pub(super) fn response(status: StatusCode, code: &'static str, id: &RequestId) -> Response {
        let problem = Self {
            kind: "about:blank",
            title: status.canonical_reason().unwrap_or("Request failed"),
            status: status.as_u16(),
            code,
            request_id: id.0.clone(),
        };
        let mut response = (status, Json(problem)).into_response();
        response.headers_mut().insert(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("application/problem+json"),
        );
        response.headers_mut().insert(
            header::CONNECTION,
            header::HeaderValue::from_static("close"),
        );
        response
    }
}