tiles_proxy/
http_headers.rs1use rocket::fairing::{Fairing, Info, Kind};
4use rocket::http::Header;
5use rocket::{Request, Response};
6
7pub struct CacheControl;
11
12#[rocket::async_trait]
13impl Fairing for CacheControl {
14 fn info(&self) -> Info {
15 Info {
16 name: "Add Cache-Control header to responses",
17 kind: Kind::Response,
18 }
19 }
20
21 async fn on_response<'r>(&self, _request: &'r Request<'_>, response: &mut Response<'r>) {
22 response.set_header(Header::new(
24 "Cache-Control",
25 "public, max-age=2592000, immutable",
26 ));
27 }
28}
29
30pub struct Cors;
34
35#[rocket::async_trait]
36impl Fairing for Cors {
37 fn info(&self) -> Info {
38 Info {
39 name: "Add CORS headers to responses",
40 kind: Kind::Response,
41 }
42 }
43
44 async fn on_response<'r>(&self, _request: &'r Request<'_>, response: &mut Response<'r>) {
45 response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
46 response.set_header(Header::new(
47 "Access-Control-Allow-Methods",
48 "POST, GET, PATCH, OPTIONS",
49 ));
50 response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
51 response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
52 }
53}