union_square/proxy/headers.rs
1//! HTTP header constants and utilities for the proxy service
2//!
3//! This module centralizes all HTTP header names and header-related
4//! constants used throughout the proxy service to ensure consistency
5//! and make maintenance easier.
6
7use ::http::header;
8
9/// Custom header name for the target URL that the proxy should forward requests to
10pub const X_TARGET_URL: &str = "x-target-url";
11
12/// Header name for request ID used for tracing and correlation
13pub const X_REQUEST_ID: &str = "x-request-id";
14
15/// Header name for session ID used for grouping related requests
16pub const X_SESSION_ID: &str = "x-session-id";
17
18/// Header name for API key authentication
19pub const X_API_KEY: &str = "x-api-key";
20
21/// Authorization header prefix for bearer tokens
22pub const BEARER_PREFIX: &str = "Bearer ";
23
24/// Standard header re-exports for convenience
25pub use header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HOST, USER_AGENT};
26
27/// Well-known paths
28pub mod paths {
29 /// Default path when none is specified
30 pub const DEFAULT: &str = "/";
31
32 /// Health check endpoint path
33 pub const HEALTH: &str = "/health";
34
35 /// Metrics endpoint path
36 pub const METRICS: &str = "/metrics";
37}
38
39/// Common content types (re-exported from centralized constants)
40pub mod content_types {
41 pub use crate::providers::constants::http::content_types::*;
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_header_constants() {
50 // Ensure header names follow conventions
51 assert!(X_TARGET_URL.starts_with("x-"));
52 assert!(X_REQUEST_ID.starts_with("x-"));
53 assert!(X_SESSION_ID.starts_with("x-"));
54
55 // Ensure paths are valid
56 assert!(paths::DEFAULT.starts_with('/'));
57 assert!(paths::HEALTH.starts_with('/'));
58 assert!(paths::METRICS.starts_with('/'));
59
60 // Ensure bearer prefix has proper format
61 assert!(BEARER_PREFIX.ends_with(' '));
62 }
63}