-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cd17c3
commit f82a924
Showing
3 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use axum::extract::{Query, Request}; | ||
use axum::middleware::Next; | ||
use axum::response::IntoResponse; | ||
use std::convert::Infallible; | ||
use std::time::Duration; | ||
use tokio::time::sleep; | ||
|
||
#[derive(Debug, serde::Deserialize)] | ||
pub struct DynamicQueryParams { | ||
/// Allow a request to have a ?bslive.delay.ms=200 style param to simulate a TTFB delay | ||
#[serde(rename = "bslive.delay.ms")] | ||
delay: Option<u64>, | ||
} | ||
|
||
pub async fn dynamic_query_params_handler(req: Request, next: Next) -> impl IntoResponse { | ||
if let Ok(Query(DynamicQueryParams { delay: Some(ms) })) = Query::try_from_uri(req.uri()) { | ||
sleep(Duration::from_millis(ms)).await; | ||
} | ||
let res = next.run(req).await; | ||
Ok::<_, Infallible>(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters