Skip to content

Commit 5519000

Browse files
committed
Update keep alive to also take into account the number of request
1 parent 892a6f8 commit 5519000

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/server.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@ where
2525
Fut: Future<Output = Result<Response<Body<O>>, Exception>>,
2626
O: Read + Unpin + Send,
2727
{
28+
// TODO: make configurable
29+
let timeout_duration = Duration::from_secs(10);
30+
const MAX_REQUESTS: usize = 200;
31+
2832
let req = decode(reader).await?;
33+
let mut num_requests = 0;
2934
if let Some(mut req) = req {
30-
let headers = req.headers();
31-
let timeout_duration = match (headers.get("Connection"), headers.get("Keep-Alive")) {
32-
(Some(connection), Some(_v))
33-
if connection == http::header::HeaderValue::from_static("Keep-Alive") =>
34-
{
35-
// TODO: parse timeout
36-
Duration::from_secs(10)
35+
loop {
36+
num_requests += 1;
37+
if num_requests > MAX_REQUESTS {
38+
return Ok(());
3739
}
38-
_ => Duration::from_secs(10),
39-
};
4040

41-
loop {
4241
// TODO: what to do when the callback returns Err
4342
let mut res = encode(callback(&mut req).await?).await?;
4443
io::copy(&mut res, writer).await?;

0 commit comments

Comments
 (0)