diff --git a/examples/ssr_modes_axum/src/main.rs b/examples/ssr_modes_axum/src/main.rs index 2445cca75..4d9eb3810 100644 --- a/examples/ssr_modes_axum/src/main.rs +++ b/examples/ssr_modes_axum/src/main.rs @@ -1,7 +1,10 @@ #[cfg(feature = "ssr")] #[tokio::main] async fn main() { - use axum::Router; + use axum::{ + http::{HeaderName, HeaderValue}, + Router, + }; use leptos::{logging::log, prelude::*}; use leptos_axum::{generate_route_list, LeptosRoutes}; use ssr_modes_axum::app::*; @@ -17,7 +20,24 @@ async fn main() { let leptos_options = leptos_options.clone(); move || shell(leptos_options.clone()) }) - .fallback(leptos_axum::file_and_error_handler(shell)) + .fallback(leptos_axum::file_and_error_handler_with_context( + move || { + // if you want to add custom headers to the static file handler response, + // you can do that by providing `ResponseOptions` via context + let opts = use_context::() + .unwrap_or_default(); + opts.insert_header( + HeaderName::from_static("cross-origin-opener-policy"), + HeaderValue::from_static("same-origin"), + ); + opts.insert_header( + HeaderName::from_static("cross-origin-embedder-policy"), + HeaderValue::from_static("require-corp"), + ); + provide_context(opts); + }, + shell, + )) .with_state(leptos_options); // run our app with hyper diff --git a/integrations/axum/src/lib.rs b/integrations/axum/src/lib.rs index 0930134d1..a7819b24a 100644 --- a/integrations/axum/src/lib.rs +++ b/integrations/axum/src/lib.rs @@ -2050,7 +2050,20 @@ where let res = res.await.unwrap(); if res.status() == StatusCode::OK { - res.into_response() + let owner = Owner::new(); + owner.with(|| { + additional_context(); + let res = res.into_response(); + if let Some(response_options) = + use_context::() + { + let mut res = AxumResponse(res); + res.extend_response(&response_options); + res.0 + } else { + res + } + }) } else { let mut res = handle_response_inner( move || {