pub mod auth;
pub mod contract;
pub mod error;
pub mod health;
pub mod idempotency;
pub mod layers;
pub mod metrics;
pub mod middleware;
#[cfg(feature = "openapi")]
#[cfg_attr(docsrs, doc(cfg(feature = "openapi")))]
pub mod openapi;
pub mod pagination;
pub mod query;
pub mod rate_limit;
pub mod request_context;
pub mod trusted_proxy;
pub mod validation;
pub use crate::net::{ClientIp, ClientIpError, MAX_CLIENT_IP_LENGTH};
pub use auth::{
CurrentPrincipal, HttpAuthenticationHook, OptionalPrincipal, VerifiedAuthentication,
};
pub use contract::{
EndpointAudit, EndpointAuth, EndpointContract, EndpointContractDocument,
EndpointContractRegistry, EndpointContractSnapshot, EndpointContractSnapshotSummary,
EndpointContractValidationError, EndpointIdempotency, EndpointMethod, EndpointMethodError,
EndpointPagination, EndpointPathPattern, EndpointPermissions, EndpointPermissionsDocument,
EndpointRateLimit, EndpointRisk, EndpointRouter,
};
pub use error::{
ApiErrorBoundary, ApiProblem, ApiProblemStatusError, DEFAULT_PROBLEM_CODE, ErrorCategory,
IntoApiProblem, MAX_PROBLEM_CODE_LENGTH, MAX_PROBLEM_TYPE_LENGTH, ProblemCode, ProblemDetails,
ProblemIdentifierError, ProblemType, PublicError,
};
pub use health::HealthResponse;
pub use idempotency::{
DEFAULT_IDEMPOTENCY_MAX_BODY_BYTES, DEFAULT_IDEMPOTENCY_PROCESSING_TTL,
DEFAULT_IDEMPOTENCY_TTL, DEFAULT_MAX_IDEMPOTENCY_RECORDS,
DEFAULT_MAX_IDEMPOTENCY_STORED_HEADER_BYTES, DEFAULT_MAX_IDEMPOTENCY_STORED_RESPONSE_BYTES,
IDEMPOTENCY_KEY_HEADER_NAME, IDEMPOTENCY_REPLAYED_HEADER_NAME, IdempotencyConfig,
IdempotencyConfigError, IdempotencyHeaderError, IdempotencyKey, IdempotencyKeyError,
IdempotencyLayer, IdempotencyLease, IdempotencyRejection, IdempotencyRequestHash,
IdempotencyRequestPolicy, IdempotencyReservation, IdempotencyRuntime, IdempotencyScope,
IdempotencyService, IdempotencyStore, IdempotencyStoreError, MAX_IDEMPOTENCY_KEY_LENGTH,
MemoryIdempotencyStore, RequiredIdempotencyKey, StoredIdempotencyResponse,
idempotency_key_from_headers, idempotency_middleware, is_valid_idempotency_key,
parse_required_idempotency_key, run_idempotent_request, run_idempotent_service,
};
pub use layers::{
CorsConfig, CorsMode, CorsPolicy, CorsSettings, DEFAULT_HSTS_MAX_AGE,
DEFAULT_HTTP_REQUEST_BODY_LIMIT, DEFAULT_HTTP_TIMEOUT, EffectiveHttpRequestPolicy,
ForwardedHeadersMode, ForwardedHeadersSettings, HttpIdempotencySettings, HttpMiddlewareConfig,
HttpMiddlewareError, HttpMiddlewareSettings, HttpMiddlewareStack, HttpMiddlewareStackBuilder,
HttpRateLimitConfig, HttpRateLimitSettings, HttpRequestPolicy, HttpRequestPolicySettings,
HttpRouteRule, HttpRouteRuleSettings, RateLimitKeySourceSettings, RequestBodyLimitPolicy,
RequestBodyLimitSettings, RouteMatcher, RouteMatcherSettings, SecurityHeadersConfig,
SecurityHeadersSettings, StrictTransportSecuritySettings,
};
pub use metrics::{
HTTP_METRICS_UNMATCHED_ROUTE, HttpMetricsLayer, HttpMetricsService, MetricsResponse,
OPENMETRICS_CONTENT_TYPE, record_http_metrics,
};
pub use middleware::{
request_context_middleware, request_context_middleware_with_forwarded_policy,
};
pub use pagination::{
CursorPagination, CursorPaginationQuery, OffsetPagination, OffsetPaginationQuery,
};
pub use query::{QueryParams, deserialize_bool_from_query, deserialize_optional_u32_from_query};
pub use rate_limit::{
DEFAULT_MAX_RATE_LIMIT_BUCKETS, MAX_RATE_LIMIT_HEADER_VALUE_BYTES, RateLimitConfig,
RateLimitDecision, RateLimitError, RateLimitKeySource, RateLimitLayer, RateLimitRejection,
RateLimitRequestPolicy, RateLimitRuntime, RateLimitService, RateLimitStore,
TokenBucketRateLimiter, TrustedRateLimitHeader, enforce_rate_limit, rate_limit_middleware,
};
pub use request_context::{
CLIENT_ID_HEADER_NAME, ClientIpSource, LOCALE_HEADER_NAME, MAX_REQUEST_CONTEXT_VALUE_LENGTH,
MAX_REQUEST_ID_LENGTH, MAX_TRACEPARENT_LENGTH, MAX_USER_AGENT_LENGTH, REQUEST_ID_HEADER_NAME,
RequestContext, RequestId, RequestIdError, SESSION_ID_HEADER_NAME, TIME_ZONE_HEADER_NAME,
TRACEPARENT_HEADER_NAME, TRACEPARENT_LENGTH, TraceParent, TraceParentError,
UTC_OFFSET_HEADER_NAME, is_valid_request_id, is_valid_traceparent,
};
pub use trusted_proxy::{ForwardedHeadersPolicy, TrustedProxyConfig};
pub use validation::{FieldViolation, FieldViolations, Validate, ValidatedJson, ValidationError};
fn is_valid_route_path(path: &str) -> bool {
path.starts_with('/')
&& path.is_ascii()
&& !path.bytes().any(|byte| {
byte.is_ascii_control()
|| byte.is_ascii_whitespace()
|| matches!(byte, b'?' | b'#' | b'\\')
})
}
fn to_lower_hex(bytes: &[u8]) -> String {
const HEX: &[u8; 16] = b"0123456789abcdef";
let mut output = String::with_capacity(bytes.len() * 2);
for byte in bytes {
output.push(char::from(HEX[usize::from(byte >> 4)]));
output.push(char::from(HEX[usize::from(byte & 0x0f)]));
}
output
}