sdforge 0.4.1

Multi-protocol SDK framework with unified macro configuration
// Copyright (c) 2026 Kirky.X
// SPDX-License-Identifier: MIT
//! HTTP server implementation

use crate::core::ApiMetadata;
use crate::define_registration;
#[cfg(test)]
use crate::core::Registration;
use axum::routing::MethodRouter;

// Type imports re-exported to test modules via `use super::super::*`.
#[cfg(test)]
use axum::Router;
#[cfg(test)]
use axum::body::Body;

pub mod response;
pub mod security_headers;
pub mod version_routing;

pub use response::{build_fallback_response, build_json_response};
pub use security_headers::SecurityHeaders;
pub use version_routing::{
    VersionRouterConfig, VersionedRoute, build_version_router, version_redirect_middleware,
};

// Re-export rate-limit types when the `ratelimit` feature is enabled.
// Allows downstream users to access `RateLimitLayer`/`RateLimiter`/`LimiteronAdapter`
// via `sdforge::http::` without reaching into `sdforge::security::ratelimit::`.
#[cfg(feature = "ratelimit")]
pub use crate::security::{LimiteronAdapter, RateLimitLayer, RateLimiter};

mod http_impl;
pub use http_impl::{build, build_with_config, build_with_redirect};
#[cfg(feature = "ratelimit")]
pub use http_impl::rate_limit_layer;

// Re-export internal helpers for test access.
#[cfg(test)]
pub(crate) use http_impl::{apply_security_headers, get_or_generate_request_id, resolve_route_path};
#[cfg(all(test, feature = "mcp"))]
pub(crate) use http_impl::preserve_mcp_inventory;
#[cfg(all(test, feature = "websocket"))]
pub(crate) use http_impl::preserve_websocket_inventory;
#[cfg(all(test, feature = "grpc"))]
pub(crate) use http_impl::preserve_grpc_inventory;

/// Request ID header name
pub(crate) const X_REQUEST_ID: &str = "x-request-id";

/// HTTP route registration
#[derive(Debug, Clone)]
pub struct HttpRoute {
    /// Route path (may contain module prefix placeholders)
    path: String,
    /// Handler function (includes method routing)
    handler: MethodRouter,
    /// API metadata
    metadata: ApiMetadata,
    /// Module prefix (if any) - used for route grouping
    module_prefix: Option<String>,
}

// Generated by `define_registration!` macro for unified registration system.
define_registration!(RouteRegistration, HttpRoute, ApiMetadata);

inventory::collect!(HttpRoute);

#[cfg(test)]
mod tests;