Skip to content

How to set cache-control on Files response #584

Discussion options

You must be logged in to vote

I think I figured this out, which is to use web::scope for the static Files service, and adding a DefaultHeaders middleware just for that scope:

.service(
    web::scope("/static")
        .wrap(middleware::DefaultHeaders::new().add(("Cache-Control", "max-age=86400")))
        .service(Files::new("/", &config.static_path).prefer_utf8(true)),
)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by danieldickison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant