mycelium-http-tools 8.3.1-rc.2

Provide HTTP related elements to the mycelium project.
Documentation
use lazy_static::lazy_static;
use std::env::var_os;
use zstd::DEFAULT_COMPRESSION_LEVEL as ZSTD_DEFAULT_COMPRESSION_LEVEL;

// ? ---------------------------------------------------------------------------
// ? Configure default system constants
// ? ---------------------------------------------------------------------------

/// Default profile key
///
/// This is the default key used to store the profile in the request headers and
/// send it to the gateway downstream services.
///
pub const DEFAULT_PROFILE_KEY: &str = "x-mycelium-profile";

/// Default email key
///
/// This is the default key used to store the email in the request headers and
/// send it to the gateway downstream services.
///
pub const DEFAULT_EMAIL_KEY: &str = "x-mycelium-email";

/// Default scope key
///
/// The scope key should be used to inject the scope present on the connection
/// string into the request headers and send it to the gateway downstream
/// services.
///
pub const DEFAULT_SCOPE_KEY: &str = "x-mycelium-scope";

/// Default mycelium role key
///
/// This is the default key used to store the mycelium role in the request
/// headers and send it to the gateway downstream services.
///
pub const DEFAULT_MYCELIUM_ROLE_KEY: &str = "x-mycelium-role";

/// Default request id key
///
/// This is the default key used to store the request id in the request headers
/// and send it to the gateway downstream services.
///
pub const DEFAULT_REQUEST_ID_KEY: &str = "x-mycelium-request-id";

/// Default connection string key
///
/// This is the default key used to store the connection string in the request
/// headers and send it to the gateway downstream services.
///
pub const DEFAULT_CONNECTION_STRING_KEY: &str = "x-mycelium-connection-string";

/// Default tenant id key
///
/// This is the default key used to store the tenant id in the request headers
/// and send it to the gateway downstream services.
///
pub const DEFAULT_TENANT_ID_KEY: &str = "x-mycelium-tenant-id";

/// Default forward header key (unofficial, pre-RFC 7239)
///
/// This is the default key used to store the forward header in the request
/// headers and send it to the gateway downstream services.
///
pub const FORWARD_FOR_KEY: &str = "x-forwarded-for";

/// RFC 7239 standard Forwarded header key
///
/// The standard `Forwarded` header as defined in RFC 7239. Takes priority
/// over `X-Forwarded-For` when present. The gateway parses the `for=`
/// directive from this header to resolve the original client IP.
///
pub const RFC7239_FORWARDED_KEY: &str = "forwarded";

/// Default forwarded keys
///
/// This is the default key used to store the forwarded host, protocol and port
/// in the request headers and send it to the gateway downstream services.
///
pub const MYCELIUM_SERVICE_NAME: &str = "x-mycelium-service-name";

/// Default security group key
///
/// This is the default key used to store the security group in the request
/// headers and send it to the gateway downstream services.
///
pub const MYCELIUM_SECURITY_GROUP: &str = "x-mycelium-security-group";

/// Default forwarding keys
///
/// Such keys are used to map the headers that should be removed from the
/// downstream response before stream it back to the client.
///
pub const FORWARDING_KEYS: [&str; 9] = [
    "Host",
    "Connection",
    "Keep-Alive",
    "Proxy-Authenticate",
    "Proxy-Authorization",
    "Te",
    "Trailers",
    "Transfer-Encoding",
    "Upgrade",
];

/// Mycelium provider key
///
/// This is the key used to indicate that the request is coming from the
/// internal provider. This key should be used to validate the issuer of the
/// request.
///
pub const MYCELIUM_PROVIDER_KEY: &str = "mycelium";

/// The scope used to indicate MCP routes
pub const MYCELIUM_AI_AWARE: &str = "mycelium-ai-aware";

/// Default compression level
///
/// This is the default compression level used to compress the profile before
/// encoding to Base64.
///
pub const DEFAULT_COMPRESSION_LEVEL: i32 = ZSTD_DEFAULT_COMPRESSION_LEVEL;

// ? ---------------------------------------------------------------------------
// ? Authentication and authorization
// ? ---------------------------------------------------------------------------

lazy_static! {
    #[derive(Debug)]
    pub(crate) static ref PROFILE_FETCHING_URL: String =
        match var_os("PROFILE_FETCHING_URL") {
            Some(path) => path.into_string().unwrap(),
            None => panic!("PROFILE_FETCHING_URL not configured."),
        };
}