Line data Source code
1 : use axum::{extract::Request, middleware::Next, response::Response};
2 : use uuid::Uuid;
3 :
4 : use crate::http::headers::X_REQUEST_ID;
5 :
6 : /// This middleware function allows compute_ctl to generate its own request ID
7 : /// if one isn't supplied. The control plane will always send one as a UUID. The
8 : /// neon Postgres extension on the other hand does not send one.
9 0 : pub async fn maybe_add_request_id_header(mut request: Request, next: Next) -> Response {
10 0 : let headers = request.headers_mut();
11 0 : if !headers.contains_key(X_REQUEST_ID) {
12 0 : headers.append(X_REQUEST_ID, Uuid::new_v4().to_string().parse().unwrap());
13 0 : }
14 :
15 0 : next.run(request).await
16 0 : }
|