I have some endpoints like this clipped example:
impl Index {
#[get("/")]
fn index(&self) -> impl Future<Item = FileResponse, Error = io::Error> + Send {}
#[get("/help")]
fn help(&self) -> impl Future<Item = FileResponse, Error = io::Error> + Send {}
}
impl Assets {
#[get("/assets/*asset")]
fn asset(&self, asset: PathBuf) -> impl Future<Item = FileResponse, Error = io::Error> + Send {}
}
I'd like to set the Cache-Control header to 1 hour for index / help and 1 year for asset.
It'd be nice to have some amount of reusable code for this, instead of manually mucking about with the http::Response in each endpoint.
Some ideas I had:
-
Add a higher-order service:
ServiceBuilder::new()
.resource(Cache::new(one_hour, Index::new(config.root.clone())))
.resource(Cache::new(one_year, Assets::new(config.root)))
-
Some kind of sugar (unclear on how to implement this)
#[get("/")]
#[web(cache = one_hour)]
fn index(&self) -> impl Future<Item = FileResponse, Error = io::Error> + Send {}
Ideas and suggested direction would be appreciated.
I have some endpoints like this clipped example:
I'd like to set the
Cache-Controlheader to 1 hour forindex/helpand 1 year forasset.It'd be nice to have some amount of reusable code for this, instead of manually mucking about with the
http::Responsein each endpoint.Some ideas I had:
Add a higher-order service:
Some kind of sugar (unclear on how to implement this)
Ideas and suggested direction would be appreciated.