diff options
author | Chris Rose <offline@offby1.net> | 2023-10-03 12:36:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 19:36:16 +0000 |
commit | 573ff69749f6fa75b46780cdc3d2d438c528b082 (patch) | |
tree | 540e097a8aae3dff2e444e3d0d6c27672ed7b794 /atuin-server | |
parent | 6f803b548b56b2276eb6fbd403a606a468b36368 (diff) |
A man is not dead while his name is still spoken (#1280)
Diffstat (limited to 'atuin-server')
-rw-r--r-- | atuin-server/src/router.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/atuin-server/src/router.rs b/atuin-server/src/router.rs index 7cfcdad1a..0100822e9 100644 --- a/atuin-server/src/router.rs +++ b/atuin-server/src/router.rs @@ -2,7 +2,9 @@ use async_trait::async_trait; use atuin_common::api::ErrorResponse; use axum::{ extract::FromRequestParts, - response::IntoResponse, + http::Request, + middleware::Next, + response::{IntoResponse, Response}, routing::{delete, get, post}, Router, }; @@ -76,6 +78,18 @@ async fn teapot() -> impl IntoResponse { (http::StatusCode::IM_A_TEAPOT, "🫖") } +async fn clacks_overhead<B>(request: Request<B>, next: Next<B>) -> Response { + let mut response = next.run(request).await; + + let gnu_terry_value = "GNU Terry Pratchett"; + let gnu_terry_header = "X-Clacks-Overhead"; + + response + .headers_mut() + .insert(gnu_terry_header, gnu_terry_value.parse().unwrap()); + response +} + #[derive(Clone)] pub struct AppState<DB: Database> { pub database: DB, @@ -107,5 +121,9 @@ pub fn router<DB: Database>(database: DB, settings: Settings<DB::Settings>) -> R } .fallback(teapot) .with_state(AppState { database, settings }) - .layer(ServiceBuilder::new().layer(TraceLayer::new_for_http())) + .layer( + ServiceBuilder::new() + .layer(axum::middleware::from_fn(clacks_overhead)) + .layer(TraceLayer::new_for_http()), + ) } |