Expand description
CORS (Cross-Origin Resource Sharing) Configuration for ReasonKit Web
This module provides a strict CORS policy for the HTTP server, allowing only localhost origins for security. This is essential for MCP HTTP transport and browser-based integrations.
§Security Policy
- Allowed Origins: Only
localhostand127.0.0.1on any port - Allowed Methods: GET, POST, OPTIONS (preflight)
- Allowed Headers: Content-Type, Authorization
- Max Age: 3600 seconds (1 hour) for preflight caching
§Example
ⓘ
use reasonkit_web::cors::cors_layer;
use axum::Router;
let app = Router::new()
.route("/api/mcp", post(mcp_handler))
.layer(cors_layer());Structs§
- Cors
Config - CORS configuration options.
- Cors
Validation Result - Result of CORS validation containing diagnostic information.
Constants§
- ALLOWED_
HEADERS - Standard allowed headers for MCP HTTP transport
- ALLOWED_
METHODS - Standard allowed methods for MCP HTTP transport
- DEFAULT_
MAX_ AGE_ SECS - Default max age for preflight cache (1 hour)
Functions§
- cors_
layer - Creates a strict CORS layer that only allows localhost origins.
- cors_
layer_ permissive - Creates a permissive CORS layer for development/testing.
- cors_
layer_ with_ config - Creates a CORS layer with custom configuration.
- is_
localhost_ origin - Checks if the given origin is a localhost origin.
- validate_
origin - Validates an origin and returns detailed information.