Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework fs filters to be more configurable #1091

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

urkle
Copy link
Contributor

@urkle urkle commented Feb 8, 2024

Implements the contract like what was suggested in #209 (comment)

Right now implements

  • disabling last-modified header exposure
  • basic "weak" etag exposure option and etag checking (if match / if none match)
  • override read buffer size
  • ability to add custom headers in the response
  • basic callback to dynamically override options

Outstanding issues

  • should I use a boxed Fn<> trait instead of the fn()?
  • any other items to expose?
  • is the simple weak etag sufficient? or should we do a full etag based on the contents of the files being served?

Sample usage that allows long-cache on js/css assets but forces revalidation via etag of the main index.html (etc) pages which reference those.
This is used to server a VueJS application through warp.

#[tokio::main]
async fn main() {
   // first filter
   // sets no last-modified and enables etags
   // sets a LONG cache-control header on our assets (which cache-busting names)
  let routes = warp::path("assets").and(
            warp::fs::config()
                .last_modified(false)
                .etag(true)
                .add_header(
                    "cache-control",
                    "max-age=31536000, immutable".parse().unwrap(),
                )
                .dir("public/assets"),
        )
        // second filter
        // sets no last-modified and enables etags
        // sets no-cache cache-control header so browser will re-validate the html files in the root :)
        .or(warp::fs::config()
            .last_modified(false)
            .etag(true)
            .add_header("cache-control", "no-cache".parse().unwrap())
            .dir("public"));

  warp::serve(routes)
        .run(([127, 0, 0, 1], 3030))
        .await;
}

@urkle urkle force-pushed the feat-static-fs-options branch 4 times, most recently from 0ceb619 to 50f2df3 Compare February 8, 2024 16:25
@urkle urkle force-pushed the feat-static-fs-options branch from 50f2df3 to 3b782a2 Compare August 8, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant