pub struct BodyPace { /* private fields */ }Expand description
A limit on how fast a response body is sent: so many bytes a second,
once the first after of them are out.
It is kept by what has been sent and how long that has taken, not by a pause per chunk: the time the sending itself takes is part of the time a body is given, so a client that reads slowly is not slowed down a second time. Time that was not used is not saved up.
Implementations§
Source§impl BodyPace
impl BodyPace
Sourcepub fn new(rate: u64, after: u64) -> Self
pub fn new(rate: u64, after: u64) -> Self
rate bytes a second, at least one; the first after bytes as
fast as they go.
Sourcepub fn delay(&mut self, len: usize) -> Option<Duration>
pub fn delay(&mut self, len: usize) -> Option<Duration>
How long to wait after a chunk of len bytes, for it and what
went before it to have taken their time at the rate: None when
the body is on time, or not limited yet. For whoever writes the
chunks itself, and asks between one and the next.
Sourcepub fn delay_before(&mut self, len: usize) -> Option<Duration>
pub fn delay_before(&mut self, len: usize) -> Option<Duration>
How long to wait before a chunk of len bytes, for what went
before it to have taken its time: nothing for the first chunk,
which is how a body that is written in one piece is not held back
at all. For whoever is asked before a chunk is written, and has
the wait done for it (the proxy, by pingora).