tower_web/middleware/cors/
middleware.rs

1use super::{Config, CorsService};
2use middleware::Middleware;
3
4use http;
5use util::http::HttpService;
6
7use std::sync::Arc;
8
9/// Middleware providing an implementation of the CORS specification.
10#[derive(Debug)]
11pub struct CorsMiddleware {
12    config: Arc<Config>,
13}
14
15impl CorsMiddleware {
16    pub(super) fn new(config: Config) -> CorsMiddleware {
17        let config = Arc::new(config);
18        CorsMiddleware { config }
19    }
20}
21
22impl<S> Middleware<S> for CorsMiddleware
23where
24    S: HttpService,
25{
26    type Request = http::Request<S::RequestBody>;
27    type Response = http::Response<Option<S::ResponseBody>>;
28    type Error = S::Error;
29    type Service = CorsService<S>;
30
31    fn wrap(&self, service: S) -> Self::Service {
32        CorsService::new(service, self.config.clone())
33    }
34}