diff options
| author | Xe Iaso <me@christine.website> | 2022-03-21 15:17:11 +0000 |
|---|---|---|
| committer | Xe Iaso <me@christine.website> | 2022-03-21 15:17:34 +0000 |
| commit | cc3825aacc94c7a572ed46900a01c8df9e008141 (patch) | |
| tree | 15cec7a8de0021691638e51313bcf92398da9a4b | |
| parent | 3fb4c5ae0cd296cfc7b68f83d8711c0fbd639036 (diff) | |
| download | xesite-cc3825aacc94c7a572ed46900a01c8df9e008141.tar.xz xesite-cc3825aacc94c7a572ed46900a01c8df9e008141.zip | |
fix headers
Signed-off-by: Xe Iaso <me@christine.website>
| -rw-r--r-- | src/main.rs | 64 |
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 |
