mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-17 21:20:37 +00:00
This matches the authorization middleware. --------- Signed-off-by: Tristan Partin <tristan@neon.tech> Co-authored-by: Mikhail Kot <mikhail@neon.tech>
17 lines
646 B
Rust
17 lines
646 B
Rust
use axum::{extract::Request, middleware::Next, response::Response};
|
|
use uuid::Uuid;
|
|
|
|
use crate::http::headers::X_REQUEST_ID;
|
|
|
|
/// This middleware function allows compute_ctl to generate its own request ID
|
|
/// if one isn't supplied. The control plane will always send one as a UUID. The
|
|
/// neon Postgres extension on the other hand does not send one.
|
|
pub async fn maybe_add_request_id_header(mut request: Request, next: Next) -> Response {
|
|
let headers = request.headers_mut();
|
|
if !headers.contains_key(X_REQUEST_ID) {
|
|
headers.append(X_REQUEST_ID, Uuid::new_v4().to_string().parse().unwrap());
|
|
}
|
|
|
|
next.run(request).await
|
|
}
|