I use http-body to parse the body of an endless Transfer-Encoding: Chunked stream.
let frame = response.frame().await.expect("Stream ended").expect("Failed to read frame");
let Ok(data) = frame.into_data() else {
// frame is trailers, ignored
continue;
};
let decoded = serde_json::from_slice(&data)?;
// ...
But as I've discovered, under certain conditions data is incomplete. When complete it ends in \n.
To fix it I have a buffer that I only parse out the part of [0..(index of first b'\n'] and remove it from the buffer.
This leaves me with the following questions:
- Is this expected behavior from
Frame? Having a partial piece in there?
- Is the
\n a left-over from the Chunked separator \r\n?
I use
http-bodyto parse the body of an endlessTransfer-Encoding: Chunkedstream.But as I've discovered, under certain conditions
datais incomplete. When complete it ends in\n.To fix it I have a buffer that I only parse out the part of
[0..(index of first b'\n']and remove it from the buffer.This leaves me with the following questions:
Frame? Having a partial piece in there?\na left-over from the Chunked separator\r\n?