Switch from axum to axum-core and http
This will hopefully keep dependency churn lower.
This commit is contained in:
parent
cbc313ec52
commit
f4b3588ae1
3 changed files with 25 additions and 7 deletions
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"rust-analyzer.cargo.features": "all"
|
||||||
|
}
|
||||||
|
|
@ -9,8 +9,12 @@ license = "MIT OR Apache-2.0"
|
||||||
keywords = ["html", "svg", "mathml", "hiccup"]
|
keywords = ["html", "svg", "mathml", "hiccup"]
|
||||||
categories = ["web-programming", "template-engine"]
|
categories = ["web-programming", "template-engine"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
axum = ["dep:axum-core", "dep:http"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.7.9", optional = true }
|
axum-core = { version = "0.4.5", optional = true }
|
||||||
|
http = { version = "1.1.0", optional = true }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
rust.unsafe_code = { level = "forbid", priority = 1 }
|
rust.unsafe_code = { level = "forbid", priority = 1 }
|
||||||
|
|
|
||||||
23
src/axum.rs
23
src/axum.rs
|
|
@ -1,14 +1,25 @@
|
||||||
use axum::{
|
use axum_core::response::IntoResponse;
|
||||||
http::StatusCode,
|
use http::{header, HeaderValue, StatusCode};
|
||||||
response::{Html, IntoResponse},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{Document, Render};
|
use crate::{Document, Render};
|
||||||
|
|
||||||
|
// https://github.com/hyperium/mime/blob/ce5062d216bf757a0ed3fc70f0fe255d1c8d74ae/src/lib.rs#L753
|
||||||
|
const TEXT_HTML_UTF_8: &str = "text/html; charset=utf-8";
|
||||||
|
|
||||||
impl IntoResponse for Document {
|
impl IntoResponse for Document {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum_core::response::Response {
|
||||||
match self.render_to_string() {
|
match self.render_to_string() {
|
||||||
Ok(html) => Html(html).into_response(),
|
// Keeping dependency churn low by manually reimplementing
|
||||||
|
// https://github.com/tokio-rs/axum/blob/b5a01092216d0fa5ab950cbd7030ebcc925ceb33/axum/src/response/mod.rs#L40-L54
|
||||||
|
Ok(html) => (
|
||||||
|
[(
|
||||||
|
header::CONTENT_TYPE,
|
||||||
|
HeaderValue::from_static(TEXT_HTML_UTF_8),
|
||||||
|
)],
|
||||||
|
html,
|
||||||
|
)
|
||||||
|
.into_response(),
|
||||||
|
|
||||||
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue