Made sure the get_status and update_response callbacks are used correctly

This commit is contained in:
Slatian 2023-10-29 18:20:57 +01:00
parent 51aa05fe13
commit 5ac056ef99
2 changed files with 8 additions and 5 deletions

View File

@ -34,7 +34,7 @@ where S: MycQuerySettings<F>, 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
///

View File

@ -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::<Full<Bytes>>::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