Add Html response type

This commit is contained in:
David Pedersen
2021-05-31 10:20:07 +02:00
parent 0b2f791bf4
commit 6822766165
5 changed files with 57 additions and 24 deletions
+15
View File
@@ -92,6 +92,21 @@ where
}
}
pub struct Html<T>(pub T);
impl<T> IntoResponse<Body> for Html<T>
where
T: Into<Bytes>,
{
fn into_response(self) -> Result<Response<Body>, Error> {
let bytes = self.0.into();
let mut res = Response::new(Body::from(bytes));
res.headers_mut()
.insert(header::CONTENT_TYPE, HeaderValue::from_static("text/html"));
Ok(res)
}
}
#[derive(Debug, Copy, Clone)]
pub struct Empty;