mz_frontegg_mock/middleware/
latency.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use crate::server::Context;
11use axum::{
12    extract::{Request, State},
13    middleware::Next,
14    response::IntoResponse,
15};
16use std::sync::Arc;
17
18pub async fn latency_middleware(
19    State(context): State<Arc<Context>>,
20    request: Request,
21    next: Next,
22) -> impl IntoResponse {
23    if let Some(latency) = context.latency {
24        tokio::time::sleep(latency).await;
25    }
26    next.run(request).await
27}