diff --git a/src/mycelium/view.rs b/src/mycelium/view.rs index 2539302..1550a05 100644 --- a/src/mycelium/view.rs +++ b/src/mycelium/view.rs @@ -34,7 +34,7 @@ where S: MycQuerySettings, F: MycFormat { /// Update non-API responses after they have been built. /// /// Useful for setting extra headers. Does noting by default. - fn update_response(&self, _settings: &S, _response: &mut Response) {} + fn update_response(&self, _response: &mut Response, _settings: &S) {} /// Return an API-Response /// diff --git a/src/templating_engine.rs b/src/templating_engine.rs index 01c1919..d32da16 100644 --- a/src/templating_engine.rs +++ b/src/templating_engine.rs @@ -56,15 +56,18 @@ impl Engine { settings.initalize_template_context(&mut context); match self.tera.render(&(template_name.clone()+&format.get_file_extension()), &context) { - Ok(text) => - ( + Ok(text) => { + let mut response = ( [( header::CONTENT_TYPE, HeaderValue::from_str(mime_type.as_ref()) .expect("MimeType should always be a valid header value.") )], Into::>::into(text), - ).into_response(), + ).into_response(); + view.update_response(&mut response, &settings); + response + }, Err(e) => { println!("There was an error while rendering template {}: {e:?}", template_name); ( @@ -79,7 +82,7 @@ impl Engine { } }; // Set status code - if status_code != StatusCode::OK { + if response.status() == StatusCode::OK && status_code != StatusCode::OK { *response.status_mut() = status_code; } // Set cookies