diff options
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/blog.rs | 13 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 3 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/handlers/blog.rs b/src/handlers/blog.rs index f6aae06..6c66c97 100644 --- a/src/handlers/blog.rs +++ b/src/handlers/blog.rs @@ -4,6 +4,7 @@ use axum::{ extract::{Extension, Path}, response::Html, }; +use http::HeaderMap; use lazy_static::lazy_static; use prometheus::{opts, register_int_counter_vec, IntCounterVec}; use std::sync::Arc; @@ -72,10 +73,11 @@ pub async fn series_view( Ok(Html(result)) } -#[instrument(skip(state))] +#[instrument(skip(state, headers))] pub async fn post_view( Path(name): Path<String>, Extension(state): Extension<Arc<State>>, + headers: HeaderMap, ) -> Result { let mut want: Option<Post> = None; @@ -85,6 +87,13 @@ pub async fn post_view( } } + let referer = if let Some(referer) = headers.get(http::header::REFERER) { + let referer = referer.to_str()?.to_string(); + Some(referer) + } else { + None + }; + match want { None => Err(super::Error::PostNotFound(name)), Some(post) => { @@ -93,7 +102,7 @@ pub async fn post_view( .inc(); let body = templates::Html(post.body_html.clone()); let mut result: Vec<u8> = vec![]; - templates::blogpost_html(&mut result, post, body)?; + templates::blogpost_html(&mut result, post, body, referer)?; Ok(Html(result)) } } diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 97e0cb2..fa8203c 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -130,6 +130,9 @@ pub enum Error { #[error("axum http error: {0}")] AxumHTTP(#[from] axum::http::Error), + + #[error("string conversion error: {0}")] + ToStr(#[from] http::header::ToStrError), } pub type Result<T = Html<Vec<u8>>> = std::result::Result<T, Error>; |
