Expand description
CORS middleware for hyper 1.x.
Cors is a hyper::service::Service that wraps an inner service and applies the
Cross-Origin Resource Sharing protocol to every request.
Preflight requests (OPTIONS with Access-Control-Request-Method) are short-circuited
by default, so the inner service never sees them.
§Example
use std::{convert::Infallible, time::Duration};
use http::Method;
use hyper::{Request, Response, service::Service, body::Incoming};
use http_body_util::Full;
use bytes::Bytes;
use hyper_cors::{Any, Cors};
async fn handle(_req: Request<Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
Ok(Response::new(Full::new(Bytes::from("ok"))))
}
let svc = hyper_cors::builder()
.allow_origin(Any)
.allow_methods([Method::GET, Method::POST])
.max_age(Duration::from_secs(600))
.build(handle);Structs§
- Allow
Credentials - Configuration for the
Access-Control-Allow-Credentialsheader. - Allow
Headers - Configuration for the
Access-Control-Allow-Headersheader. - Allow
Methods - Configuration for the
Access-Control-Allow-Methodsheader. - Allow
Origin - Configuration for the
Access-Control-Allow-Originheader. - Any
- Sentinel for the wildcard
*origin. - Config
Error - Error returned by
CorsBuilder::try_buildwhen the configuration violates a Fetch-mandated incompatibility. - Cors
- CORS middleware.
- Cors
Builder - Builder for
Cors. - Expose
Headers - Configuration for the
Access-Control-Expose-Headersheader. - MaxAge
- Configuration for the
Access-Control-Max-Ageheader. - Vary
- Configuration for the
Varyheader.
Functions§
- builder
- Returns a new
CorsBuilderwith default settings.