From 57e9132a30146cf94d6ced9cdfa349f0867719dc Mon Sep 17 00:00:00 2001 From: Arjen <4867268+atezet@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:27:02 +0200 Subject: [PATCH 1/4] Fix typos in README.md --- README.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 88d158c..0cd2c0c 100644 --- a/README.md +++ b/README.md @@ -69,17 +69,17 @@ async fn main() { An instance of the `MemoryServe` struct can be configured by calling the following configuration methods: -| method | Default value | Description | -|--------|---------------|-------------| -| `[MemoryServe::index_file]` | `Some("/index.html")` | Which file to serve on the route "/" -| `[MemoryServe::fallback]` | `None` | Which file to serve if no routed matched the request -| `[MemoryServe::fallback_status]` | `StatusCode::NOT_FOUND` | The HTTP status code to routes that did not match -| `[MemoryServe::enable_gzip]` | `true` | Allow to serve gzip encoded files -| `[MemoryServe::enable_brotli]` | `true` | Allow to serve brotli encoded files -| `[MemoryServe::html_cache_control]` | `CacheConrol::Short` | Cache control header to serve on HTML files -| `[MemoryServe::cache_control]` | `CacheConrol::Medium` | Cache control header to serve on other files -| `[MemoryServe::add_alias]` | `[]` | Create a route / file alias -| `[MemoryServe::enable_clean_url]` | `false` | Enable clean URLs +| method | Default value | Description | +| ----------------------------------- | ----------------------- | ---------------------------------------------------- | +| `[MemoryServe::index_file]` | `Some("/index.html")` | Which file to serve on the route "/" | +| `[MemoryServe::fallback]` | `None` | Which file to serve if no routed matched the request | +| `[MemoryServe::fallback_status]` | `StatusCode::NOT_FOUND` | The HTTP status code to routes that did not match | +| `[MemoryServe::enable_gzip]` | `true` | Allow to serve gzip encoded files | +| `[MemoryServe::enable_brotli]` | `true` | Allow to serve brotli encoded files | +| `[MemoryServe::html_cache_control]` | `CacheControl::Short` | Cache control header to serve on HTML files | +| `[MemoryServe::cache_control]` | `CacheControl::Medium` | Cache control header to serve on other files | +| `[MemoryServe::add_alias]` | `[]` | Create a route / file alias | +| `[MemoryServe::enable_clean_url]` | `false` | Enable clean URLs | See `Cache control` for the cache control options. @@ -116,10 +116,10 @@ Example output: There are 5 different values to choose from for the cache-control settings: -| Option | Description | Value | -|--------|-------------|-------| -| `[CacheControl::Long]` | clients can keep assets that have cache busting for a year | `max-age=31536000, immutable` -| `[CacheControl::Medium]` | assets without cache busting are revalidated after a day and can be kept for a week | `max-age=604800, stale-while-revalidate=86400` -| `[CacheControl::Short]` | cache kept for max 5 minutes, only at the client (not in a proxy) | `max-age:300, private` -| `[CacheControl::NoCache]` | do not cache if freshness is really vital | `no-cache` -| `[CacheControl::Custom]` | Custom value | *user defined* +| Option | Description | Value | +| ------------------------- | ----------------------------------------------------------------------------------- | ---------------------------------------------- | +| `[CacheControl::Long]` | clients can keep assets that have cache busting for a year | `max-age=31536000, immutable` | +| `[CacheControl::Medium]` | assets without cache busting are revalidated after a day and can be kept for a week | `max-age=604800, stale-while-revalidate=86400` | +| `[CacheControl::Short]` | cache kept for max 5 minutes, only at the client (not in a proxy) | `max-age:300, private` | +| `[CacheControl::NoCache]` | do not cache if freshness is really vital | `no-cache` | +| `[CacheControl::Custom]` | Custom value | _user defined_ | From 197064ff928b5e64ca719cb7824cd37d7730be74 Mon Sep 17 00:00:00 2001 From: Arjen <4867268+atezet@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:48:40 +0200 Subject: [PATCH 2/4] Fix links --- README.md | 44 ++++++++++++++++++++--------------------- memory-serve/src/lib.rs | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0cd2c0c..b763ec1 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,12 @@ memory-serve is designed to work with [axum](https://github.com/tokio-rs/axum) ## Usage Provide a relative path to the directory containing your static assets -to the `load_assets!` macro. This macro creates a data structure intended to -be consumed by `[MemoryServe::new]`. Calling `[MemoryServe::into_router()]` on +to the [`load_assets!`] macro. This macro creates a data structure intended to +be consumed by [`MemoryServe::new`]. Calling [`MemoryServe::into_router()`] on the resulting instance produces a axum -[Router](https://docs.rs/axum/latest/axum/routing/struct.Router.html) that +[`Router`](https://docs.rs/axum/latest/axum/routing/struct.Router.html) that can either be merged in another `Router` or used directly in a server by -calling `Router::into_make_service()`. +calling [`Router::into_make_service()`](https://docs.rs/axum/latest/axum/routing/struct.Router.html#method.into_make_service). ## Example @@ -71,17 +71,17 @@ the following configuration methods: | method | Default value | Description | | ----------------------------------- | ----------------------- | ---------------------------------------------------- | -| `[MemoryServe::index_file]` | `Some("/index.html")` | Which file to serve on the route "/" | -| `[MemoryServe::fallback]` | `None` | Which file to serve if no routed matched the request | -| `[MemoryServe::fallback_status]` | `StatusCode::NOT_FOUND` | The HTTP status code to routes that did not match | -| `[MemoryServe::enable_gzip]` | `true` | Allow to serve gzip encoded files | -| `[MemoryServe::enable_brotli]` | `true` | Allow to serve brotli encoded files | -| `[MemoryServe::html_cache_control]` | `CacheControl::Short` | Cache control header to serve on HTML files | -| `[MemoryServe::cache_control]` | `CacheControl::Medium` | Cache control header to serve on other files | -| `[MemoryServe::add_alias]` | `[]` | Create a route / file alias | -| `[MemoryServe::enable_clean_url]` | `false` | Enable clean URLs | - -See `Cache control` for the cache control options. +| [`MemoryServe::index_file`] | `Some("/index.html")` | Which file to serve on the route "/" | +| [`MemoryServe::fallback`] | `None` | Which file to serve if no routed matched the request | +| [`MemoryServe::fallback_status`] | `StatusCode::NOT_FOUND` | The HTTP status code to routes that did not match | +| [`MemoryServe::enable_gzip`] | `true` | Allow to serve gzip encoded files | +| [`MemoryServe::enable_brotli`] | `true` | Allow to serve brotli encoded files | +| [`MemoryServe::html_cache_control`] | `CacheControl::Short` | Cache control header to serve on HTML files | +| [`MemoryServe::cache_control`] | `CacheControl::Medium` | Cache control header to serve on other files | +| [`MemoryServe::add_alias`] | `[]` | Create a route / file alias | +| [`MemoryServe::enable_clean_url`] | `false` | Enable clean URLs | + +See [`Cache control`](#cache-control) for the cache control options. ## Logging @@ -93,8 +93,8 @@ WARN skipping file "static/empty.txt": file empty ``` When running the resulting executable, all registered routes and asset -sizes are logged using the [tracing](https://github.com/tokio-rs/tracing) -crate. To print or log them, use `tracing-subscriber`. +sizes are logged using the [`tracing`](https://docs.rs/tracing/latest/tracing/) +crate. To print or log them, use [`tracing-subscriber`](https://docs.rs/tracing/latest/tracing_subscriber/). Example output: ```txt @@ -118,8 +118,8 @@ There are 5 different values to choose from for the cache-control settings: | Option | Description | Value | | ------------------------- | ----------------------------------------------------------------------------------- | ---------------------------------------------- | -| `[CacheControl::Long]` | clients can keep assets that have cache busting for a year | `max-age=31536000, immutable` | -| `[CacheControl::Medium]` | assets without cache busting are revalidated after a day and can be kept for a week | `max-age=604800, stale-while-revalidate=86400` | -| `[CacheControl::Short]` | cache kept for max 5 minutes, only at the client (not in a proxy) | `max-age:300, private` | -| `[CacheControl::NoCache]` | do not cache if freshness is really vital | `no-cache` | -| `[CacheControl::Custom]` | Custom value | _user defined_ | +| [`CacheControl::Long`] | clients can keep assets that have cache busting for a year | `max-age=31536000, immutable` | +| [`CacheControl::Medium`] | assets without cache busting are revalidated after a day and can be kept for a week | `max-age=604800, stale-while-revalidate=86400` | +| [`CacheControl::Short`] | cache kept for max 5 minutes, only at the client (not in a proxy) | `max-age:300, private` | +| [`CacheControl::NoCache`] | do not cache if freshness is really vital | `no-cache` | +| [`CacheControl::Custom`] | Custom value | _user defined_ | diff --git a/memory-serve/src/lib.rs b/memory-serve/src/lib.rs index aa89b4f..7efeee3 100644 --- a/memory-serve/src/lib.rs +++ b/memory-serve/src/lib.rs @@ -16,7 +16,7 @@ pub use crate::{asset::Asset, cache_control::CacheControl}; /// Macro to load a directory of static files into the resulting binary /// (possibly compressed) and create a data structure of (meta)data -/// as an input for [MemoryServe::new] +/// as an input for [`MemoryServe::new`] pub use memory_serve_macros::load_assets; #[derive(Debug, Clone, Copy)] From 12f9ee4652b231c507fe78924672418d29137e4f Mon Sep 17 00:00:00 2001 From: Arjen <4867268+atezet@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:48:56 +0200 Subject: [PATCH 3/4] Fix enum description --- memory-serve/src/cache_control.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/memory-serve/src/cache_control.rs b/memory-serve/src/cache_control.rs index d231a6c..8e38444 100644 --- a/memory-serve/src/cache_control.rs +++ b/memory-serve/src/cache_control.rs @@ -4,10 +4,15 @@ use axum::http::{header::CACHE_CONTROL, HeaderName, HeaderValue}; /// See [Cache control](index.html#cache-control) #[derive(Debug, Clone, Copy)] pub enum CacheControl { + /// clients can keep assets that have cache busting for a year: `"max-age=31536000, immutable"` Long, + /// assets without cache busting are revalidated after a day and can be kept for a week: `"max-age=604800, stale-while-revalidate=86400"` Medium, + /// cache kept for max 5 minutes, only at the client (not in a proxy): `"max-age:300, private"` Short, + /// do not cache if freshness is really vital: `"no-cache"` NoCache, + /// custom value Custom(&'static str), } @@ -15,19 +20,15 @@ impl CacheControl { pub(crate) fn as_header(&self) -> (HeaderName, HeaderValue) { let value = match self { Self::Long => { - // clients can keep assets that have cache busting for a year "max-age=31536000, immutable" } Self::Medium => { - // assets without cache busting are revalidated after a day and can be kept for a week "max-age=604800, stale-while-revalidate=86400" } Self::Short => { - // cache kept for max 5 minutes, only at the client (not in a proxy) "max-age:300, private" } Self::NoCache => { - // do not cache if freshness is really vital "no-cache" } Self::Custom(value) => value, From c2a63e379a97d64e684d0f856774e5d93a01bec0 Mon Sep 17 00:00:00 2001 From: Arjen <4867268+atezet@users.noreply.github.com> Date: Mon, 22 Jul 2024 08:44:53 +0200 Subject: [PATCH 4/4] Cargo fmt --- memory-serve/src/cache_control.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/memory-serve/src/cache_control.rs b/memory-serve/src/cache_control.rs index 8e38444..13126cd 100644 --- a/memory-serve/src/cache_control.rs +++ b/memory-serve/src/cache_control.rs @@ -19,18 +19,10 @@ pub enum CacheControl { impl CacheControl { pub(crate) fn as_header(&self) -> (HeaderName, HeaderValue) { let value = match self { - Self::Long => { - "max-age=31536000, immutable" - } - Self::Medium => { - "max-age=604800, stale-while-revalidate=86400" - } - Self::Short => { - "max-age:300, private" - } - Self::NoCache => { - "no-cache" - } + Self::Long => "max-age=31536000, immutable", + Self::Medium => "max-age=604800, stale-while-revalidate=86400", + Self::Short => "max-age:300, private", + Self::NoCache => "no-cache", Self::Custom(value) => value, };