mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2024-11-10 00:27:21 +01:00
Made sure the get_status and update_response callbacks are used correctly
This commit is contained in:
parent
51aa05fe13
commit
5ac056ef99
@ -34,7 +34,7 @@ where S: MycQuerySettings<F>, F: MycFormat {
|
|||||||
/// Update non-API responses after they have been built.
|
/// Update non-API responses after they have been built.
|
||||||
///
|
///
|
||||||
/// Useful for setting extra headers. Does noting by default.
|
/// 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
|
/// Return an API-Response
|
||||||
///
|
///
|
||||||
|
@ -56,15 +56,18 @@ impl Engine {
|
|||||||
settings.initalize_template_context(&mut context);
|
settings.initalize_template_context(&mut context);
|
||||||
|
|
||||||
match self.tera.render(&(template_name.clone()+&format.get_file_extension()), &context) {
|
match self.tera.render(&(template_name.clone()+&format.get_file_extension()), &context) {
|
||||||
Ok(text) =>
|
Ok(text) => {
|
||||||
(
|
let mut response = (
|
||||||
[(
|
[(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
HeaderValue::from_str(mime_type.as_ref())
|
HeaderValue::from_str(mime_type.as_ref())
|
||||||
.expect("MimeType should always be a valid header value.")
|
.expect("MimeType should always be a valid header value.")
|
||||||
)],
|
)],
|
||||||
Into::<Full<Bytes>>::into(text),
|
Into::<Full<Bytes>>::into(text),
|
||||||
).into_response(),
|
).into_response();
|
||||||
|
view.update_response(&mut response, &settings);
|
||||||
|
response
|
||||||
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("There was an error while rendering template {}: {e:?}", template_name);
|
println!("There was an error while rendering template {}: {e:?}", template_name);
|
||||||
(
|
(
|
||||||
@ -79,7 +82,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Set status code
|
// Set status code
|
||||||
if status_code != StatusCode::OK {
|
if response.status() == StatusCode::OK && status_code != StatusCode::OK {
|
||||||
*response.status_mut() = status_code;
|
*response.status_mut() = status_code;
|
||||||
}
|
}
|
||||||
// Set cookies
|
// Set cookies
|
||||||
|
Loading…
Reference in New Issue
Block a user