Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A man is not dead while his name is still spoken #1280

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions atuin-server/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()),
)
}