diff --git a/examples/actix/Cargo.toml b/examples/actix/Cargo.toml index 42e6f93..ef80cd3 100644 --- a/examples/actix/Cargo.toml +++ b/examples/actix/Cargo.toml @@ -12,4 +12,4 @@ ructe = { path = "../..", features = ["sass", "mime03"] } [dependencies] actix-web = "4.2.1" mime = "0.3" -env_logger = "0.10.0" +env_logger = "0.11.3" diff --git a/examples/axum/Cargo.toml b/examples/axum/Cargo.toml index 14ec76d..179ae87 100644 --- a/examples/axum/Cargo.toml +++ b/examples/axum/Cargo.toml @@ -9,8 +9,8 @@ build = "src/build.rs" ructe = { path = "../..", features = ["sass", "mime03"] } [dependencies] -axum = { version = "0.6.2", features = ["headers"] } -env_logger = "0.10.0" -headers = "0.3.8" +axum = "0.7.5" +env_logger = "0.11.3" +log = "0.4.21" mime = "0.3" tokio = { version = "1.21.2", default-features = false, features = ["rt-multi-thread", "macros"] } diff --git a/examples/axum/src/main.rs b/examples/axum/src/main.rs index ed18bae..ef19cbb 100644 --- a/examples/axum/src/main.rs +++ b/examples/axum/src/main.rs @@ -1,16 +1,12 @@ use axum::{ extract::Path, - http::StatusCode, + http::{header, StatusCode}, response::{IntoResponse, Response}, routing::get, - Router, Server, TypedHeader, + Router, }; -use headers::{ContentType, Expires}; -use std::{ - io::{self, Write}, - time::{Duration, SystemTime}, -}; +use std::io::{self, Write}; use templates::statics::StaticFile; @@ -38,15 +34,18 @@ async fn home_page() -> impl IntoResponse { /// Handler for static files. /// Create a response from the file data with a correct content type /// and a far expires header (or a 404 if the file does not exist). -async fn static_files(Path(filename): Path) -> impl IntoResponse { - /// A duration to add to current time for a far expires header. - static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60); +async fn static_files(Path(filename): Path) -> Response { match StaticFile::get(&filename) { Some(data) => { - let far_expires = SystemTime::now() + FAR; ( - TypedHeader(ContentType::from(data.mime.clone())), - TypedHeader(Expires::from(far_expires)), + [ + (header::CONTENT_TYPE, data.mime.as_ref()), + ( + header::CACHE_CONTROL, + // max age is 180 days (given in seconds) + "public, max_age=15552000, immutable", + ), + ], data.content, ) .into_response() @@ -79,7 +78,7 @@ async fn make_error() -> Result { /// The error type that can be returned from resource handlers. /// /// This needs to be convertible from any error types used with `?` in -/// handlers, and implement the actix ResponseError type. +/// handlers, and implement the axum [IntoResponse] trait. #[derive(Debug)] enum ExampleAppError { ParseInt(std::num::ParseIntError), @@ -139,8 +138,11 @@ fn error_response( #[tokio::main] async fn main() { env_logger::init(); - Server::bind(&"0.0.0.0:3000".parse().unwrap()) - .serve(app().into_make_service()) + + let listener = + tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); + log::info!("Listening on {}.", listener.local_addr().unwrap()); + axum::serve(listener, app().into_make_service()) .await .unwrap() } diff --git a/examples/warp03/Cargo.toml b/examples/warp03/Cargo.toml index d5e889d..59d19b2 100644 --- a/examples/warp03/Cargo.toml +++ b/examples/warp03/Cargo.toml @@ -12,6 +12,6 @@ ructe = { path = "../..", features = ["warp03", "sass"] } [dependencies] warp = "0.3.0" mime = "0.3.0" -env_logger = "0.10.0" +env_logger = "0.11.3" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } log = "0.4.14"