I'm new in Rust and Rocket. I mount my static files in Rocket as follows:
.mount("/", StaticFiles::new("static", options))
It works good for images or styles but it's not quite what I expect from adding of scripts. I want to use compressed script files like *.js.gz instead of *.js. The HTML that links the script looks like:
<script type="text/javascript" src="/scripts/index.js.gz"></script>
How can I add headers to response in order to allow the use of compressed scripts? I assume I shouldn't use rocket_contrib::serve::StaticFiles for script files here. In ASP.NET Core I do this as follows:
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = content =>
{
if (!content.File.Name.EndsWith(".js.gz")) return;
content.Context.Response.Headers["Content-Type"] = "text/javascript";
content.Context.Response.Headers["Content-Encoding"] = "gzip";
}
});
Is there the same way for Rust-Rocket? Thanks!