ahecha_html/integrations/
axum.rs1use axum_core::{
2 body::{self, boxed},
3 response::{IntoResponse, Response},
4};
5use http::{header::LOCATION, HeaderValue, StatusCode};
6use http_body::{Empty, Full};
7
8use crate::{Node, RenderString};
9
10impl IntoResponse for Node {
11 fn into_response(self) -> Response {
12 match self.get_redirect() {
13 Some((status_code, location)) => {
14 let mut res = Response::new(boxed(Empty::new()));
15 *res.status_mut() = status_code;
16 res.headers_mut().insert(
17 LOCATION,
18 HeaderValue::try_from(location.to_string()).expect("URI isn't a valid header value"),
19 );
20 res
21 }
22 None => {
23 let body = body::boxed(Full::from(self.render()));
24
25 Response::builder()
26 .header("Content-Type", "text/html")
27 .status(StatusCode::OK)
28 .body(body)
29 .unwrap()
30 }
31 }
32 }
33}