aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe Iaso <me@christine.website>2022-03-21 15:17:11 +0000
committerXe Iaso <me@christine.website>2022-03-21 15:17:34 +0000
commitcc3825aacc94c7a572ed46900a01c8df9e008141 (patch)
tree15cec7a8de0021691638e51313bcf92398da9a4b
parent3fb4c5ae0cd296cfc7b68f83d8711c0fbd639036 (diff)
downloadxesite-cc3825aacc94c7a572ed46900a01c8df9e008141.tar.xz
xesite-cc3825aacc94c7a572ed46900a01c8df9e008141.zip
fix headers
Signed-off-by: Xe Iaso <me@christine.website>
-rw-r--r--src/main.rs64
1 files changed, 40 insertions, 24 deletions
diff --git a/src/main.rs b/src/main.rs
index a39ab7f..c6dc33f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,13 +4,12 @@ extern crate tracing;
use axum::{
body,
extract::Extension,
- http::header,
+ http::header::{self, HeaderValue, CACHE_CONTROL, CONTENT_TYPE},
response::{Html, Response},
routing::get,
Router,
};
use color_eyre::eyre::Result;
-use http::header::{CACHE_CONTROL, CONTENT_TYPE};
use hyper::StatusCode;
use prometheus::{Encoder, TextEncoder};
use std::{
@@ -40,6 +39,28 @@ async fn healthcheck() -> &'static str {
"OK"
}
+fn cache_header(_: &Response) -> Option<header::HeaderValue> {
+ Some(header::HeaderValue::from_static(
+ "public, max-age=3600, stale-if-error=60",
+ ))
+}
+
+fn webmention_header(_: &Response) -> Option<HeaderValue> {
+ Some(header::HeaderValue::from_static(
+ r#"<https://mi.within.website/api/webmention/accept>; rel="webmention""#,
+ ))
+}
+
+fn clacks_header(_: &Response) -> Option<HeaderValue> {
+ Some(HeaderValue::from_static("Ashlynn"))
+}
+
+fn hacker_header(_: &Response) -> Option<HeaderValue> {
+ Some(header::HeaderValue::from_static(
+ "If you are reading this, check out /signalboost to find people for your team",
+ ))
+}
+
#[tokio::main]
async fn main() -> Result<()> {
color_eyre::install()?;
@@ -59,28 +80,23 @@ async fn main() -> Result<()> {
let middleware = tower::ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
- .layer(Extension(state.clone()));
- // .layer(SetResponseHeaderLayer::overriding(
- // header::CACHE_CONTROL,
- // |_| header::HeaderValue::from_static("public, max-age=3600, stale-if-error=60"),
- // ))
- // .layer(SetResponseHeaderLayer::appending(header::LINK, |_| {
- // header::HeaderValue::from_static(
- // r#"<https://mi.within.website/api/webmention/accept>; rel="webmention""#,
- // )
- // }))
- // .layer(SetResponseHeaderLayer::appending(
- // header::HeaderName::from_static("x-clacks-overhead"),
- // |_| header::HeaderValue::from_static("Ashlynn"),
- // ))
- // .layer(SetResponseHeaderLayer::overriding(
- // header::HeaderName::from_static("x-hacker"),
- // |_| {
- // header::HeaderValue::from_static(
- // "If you are reading this, check out /signalboost to find people for your team",
- // )
- // },
- // ));
+ .layer(Extension(state.clone()))
+ .layer(SetResponseHeaderLayer::overriding(
+ header::CACHE_CONTROL,
+ cache_header,
+ ))
+ .layer(SetResponseHeaderLayer::appending(
+ header::LINK,
+ webmention_header,
+ ))
+ .layer(SetResponseHeaderLayer::appending(
+ header::HeaderName::from_static("x-clacks-overhead"),
+ clacks_header,
+ ))
+ .layer(SetResponseHeaderLayer::overriding(
+ header::HeaderName::from_static("x-hacker"),
+ hacker_header,
+ ));
let app = Router::new()
// meta