pub struct CorsPlugin { /* private fields */ }Available on crate feature
plugins only.Expand description
CORS plugin for handling cross-origin resource sharing in Tako applications.
CorsPlugin implements the TakoPlugin trait to provide comprehensive CORS support
including preflight request handling, origin validation, and response header
management. It automatically handles OPTIONS preflight requests and adds appropriate
CORS headers to all responses based on the configured policy.
§Examples
use tako::plugins::cors::{CorsPlugin, CorsBuilder};
use tako::plugins::TakoPlugin;
use tako::router::Router;
use http::Method;
// Basic setup with default permissive policy
let cors = CorsPlugin::default();
let mut router = Router::new();
router.plugin(cors);
// Custom restrictive policy for production
let prod_cors = CorsBuilder::new()
.allow_origin("https://myapp.com")
.allow_methods(&[Method::GET, Method::POST])
.allow_credentials(true)
.build();
router.plugin(prod_cors);Trait Implementations§
Source§impl Clone for CorsPlugin
impl Clone for CorsPlugin
Source§fn clone(&self) -> CorsPlugin
fn clone(&self) -> CorsPlugin
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 CorsPlugin
impl Default for CorsPlugin
Auto Trait Implementations§
impl Freeze for CorsPlugin
impl RefUnwindSafe for CorsPlugin
impl Send for CorsPlugin
impl Sync for CorsPlugin
impl Unpin for CorsPlugin
impl UnwindSafe for CorsPlugin
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