pub struct Decoder { /* private fields */ }Implementations§
Source§impl Decoder
impl Decoder
pub fn new(mode: Mode, limits: Limits) -> Self
Sourcepub fn response_to(&mut self, method: &str)
pub fn response_to(&mut self, method: &str)
Must precede response parsing. Pipelining is intentionally not provided.
pub fn reusable(&self) -> bool
Sourcepub fn wants_step(&self) -> bool
pub fn wants_step(&self) -> bool
True when the decoder holds an event that reads no input, so the host
must call receive again even with nothing new to feed
it - an empty slice will do. That event is Event::End or
Event::Upgrade. It becomes pending when the last body byte, the
final chunk or the head of a bodiless message is consumed, and after
eof ends a close-delimited body.
This is the signal a host that drives on “bytes to feed” is missing.
Such a host stops once its buffer is empty and never sees End: the
message sits finished inside the decoder, the connection is not
reusable, and only the peer’s idle timeout ends the
exchange. Loop while !input.is_empty() || decoder.wants_step(), or use
the Step contract’s condition, which covers the same case.
Sourcepub fn is_mid_message(&self) -> bool
pub fn is_mid_message(&self) -> bool
True between a message’s Event::Head and the point its end is
reached: the body, chunk framing or trailers are still being read. False
before the head (including after an Event::Informational, which is
not the message), once End or Upgrade is owed or delivered, and after
a failure. Bytes of a head the host has buffered but not yet completed
are the host’s to know; the decoder has not accepted them.
A close-delimited body is mid-message too, though EOF is its legal end:
ask eof_is_clean to tell the two apart.
Sourcepub fn eof_is_clean(&self) -> bool
pub fn eof_is_clean(&self) -> bool
Whether the transport ending now would be a clean end rather than a
truncation: exactly the cases in which eof returns Ok,
answered without changing any state. True inside a close-delimited body
and once the message is complete; false inside a framed body, before a
head arrives and after a failure. So a host whose read returned zero can
choose what to do - retry, fail with its own diagnosis, log - before it
commits to eof.
Before a head is always “not clean” here, because a client that sees EOF there got no response. A server whose connection closes while idle between requests (with no buffered head bytes) treats that as an ordinary close on its own.
pub fn reset(&mut self) -> Result<()>
pub fn receive<'a>(&mut self, input: &'a [u8]) -> Result<Step<'a>>
Sourcepub fn eof(&mut self) -> Result<()>
pub fn eof(&mut self) -> Result<()>
Declare the end of input. Ends a close-delimited body (leaving
Event::End owed, see wants_step); anywhere
eof_is_clean is false it fails the decoder.