Expand description
Cross-Origin Resource Sharing (CORS) plugin for the Churust web framework.
This crate provides a Cors plugin that intercepts every incoming HTTP
request and attaches the appropriate Access-Control-* response headers.
Preflight OPTIONS requests are short-circuited with an HTTP 204 response
so they never reach your route handlers.
§Quick start
Install the plugin via churust_core::Churust::server before calling
.build(). Use Cors::permissive for development or use Cors::new
to build a precise policy for production.
use churust_core::{Churust, Call, TestClient};
use churust_cors::Cors;
let app = Churust::server()
.install(Cors::allow_any_origin_insecure())
.routing(|r| {
r.get("/api/data", |_c: Call| async { "hello" });
})
.build();
// Actual cross-origin GET: response carries the CORS header.
let res = TestClient::new(app)
.get("/api/data")
.header("origin", "https://example.com")
.send()
.await;
assert_eq!(res.status().as_u16(), 200);
assert_eq!(res.header("access-control-allow-origin"), Some("*"));Structs§
- Cors
- CORS configuration and plugin entry point.