mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
Add Html response type
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user