update: add endless_sink debug tool
parent
d3b47d18d1
commit
6db94d3e4f
|
@ -303,6 +303,31 @@ async fn handle_server_list (
|
|||
Ok (ok_reply (s)?)
|
||||
}
|
||||
|
||||
async fn handle_endless_sink (req: Request <Body>) -> Result <Response <Body>, http::Error>
|
||||
{
|
||||
use tokio::stream::StreamExt;
|
||||
|
||||
let (_parts, mut body) = req.into_parts ();
|
||||
|
||||
let mut bytes_received = 0;
|
||||
|
||||
loop {
|
||||
let item = body.next ().await;
|
||||
|
||||
if let Some (item) = item {
|
||||
if let Ok (bytes) = &item {
|
||||
bytes_received += bytes.len ();
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug! ("Finished sinking debug bytes");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok (ok_reply (format! ("Sank {} bytes\n", bytes_received))?)
|
||||
}
|
||||
|
||||
async fn handle_endless_source (gib: usize, throttle: Option <usize>)
|
||||
-> Result <Response <Body>, http::Error>
|
||||
{
|
||||
|
@ -373,7 +398,11 @@ async fn handle_all (
|
|||
let request_code = request_code.into ();
|
||||
Ok (server_endpoint::handle_response (req, state, request_code).await?)
|
||||
}
|
||||
else if path == "/frontend/debug/endless_sink" {
|
||||
Ok (handle_endless_sink (req).await?)
|
||||
}
|
||||
else {
|
||||
error! ("Can't POST {}", path);
|
||||
Ok (error_reply (StatusCode::BAD_REQUEST, "Can't POST this")?)
|
||||
};
|
||||
}
|
||||
|
@ -415,8 +444,11 @@ async fn handle_all (
|
|||
else if rest == "endless_source_throttled" {
|
||||
Ok (handle_endless_source (1, Some (1024 / 64)).await?)
|
||||
}
|
||||
else if rest == "endless_sink" {
|
||||
Ok (error_reply (StatusCode::METHOD_NOT_ALLOWED, "Don't GET this URL, POST to it.")?)
|
||||
}
|
||||
else {
|
||||
Ok (error_reply (StatusCode::OK, "Can't route URL")?)
|
||||
Ok (error_reply (StatusCode::NOT_FOUND, "Can't route URL")?)
|
||||
}
|
||||
}
|
||||
else if path == "/" {
|
||||
|
|
|
@ -49,5 +49,8 @@ Lorem ipsum dolor set amet
|
|||
<p>
|
||||
<a href="endless_source_throttled">1 GiB random garbage data source (Throttled to 1 MiB/s)</a>
|
||||
|
||||
<p>
|
||||
<a href="endless_sink">Data sink (POST only)</a>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue