pub struct CorsMiddleware { /* private fields */ }Expand description
CORS middleware implementing the Middleware trait.
Handles both preflight (OPTIONS) and actual requests,
adding appropriate CORS headers and rejecting invalid origins/methods/headers.
Implementations§
Source§impl CorsMiddleware
impl CorsMiddleware
Sourcepub fn new(config: CorsConfig) -> Self
pub fn new(config: CorsConfig) -> Self
Create a new CORS middleware with custom config.
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive CORS config - useful for public APIs or local dev.
Allows all common methods, credentials, and common headers.
Trait Implementations§
Source§impl Clone for CorsMiddleware
impl Clone for CorsMiddleware
Source§fn clone(&self) -> CorsMiddleware
fn clone(&self) -> CorsMiddleware
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for CorsMiddleware
impl Default for CorsMiddleware
Source§fn default() -> CorsMiddleware
fn default() -> CorsMiddleware
Returns the “default value” for a type. Read more
Source§impl Middleware for CorsMiddleware
impl Middleware for CorsMiddleware
Source§fn handle<'req, 'life0, 'async_trait>(
&'life0 self,
req: Request<&'req str>,
state: Arc<McpAppState>,
next: MiddlewareNext<'req>,
) -> Pin<Box<dyn Future<Output = TransportServerResult<Response<GenericBody>>> + Send + 'async_trait>>where
Self: 'async_trait,
'req: 'async_trait,
'life0: 'async_trait,
fn handle<'req, 'life0, 'async_trait>(
&'life0 self,
req: Request<&'req str>,
state: Arc<McpAppState>,
next: MiddlewareNext<'req>,
) -> Pin<Box<dyn Future<Output = TransportServerResult<Response<GenericBody>>> + Send + 'async_trait>>where
Self: 'async_trait,
'req: 'async_trait,
'life0: 'async_trait,
Process a request, handling preflight or adding CORS headers.
- For
OPTIONSwithAccess-Control-Request-Method: performs preflight. - For other requests: passes to
next, then adds CORS headers.
Auto Trait Implementations§
impl Freeze for CorsMiddleware
impl RefUnwindSafe for CorsMiddleware
impl Send for CorsMiddleware
impl Sync for CorsMiddleware
impl Unpin for CorsMiddleware
impl UnwindSafe for CorsMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more