Skip to content

Commit

Permalink
Fix HTTP pipelined requests failing after incompletely reading a resp…
Browse files Browse the repository at this point in the history
…onse body
  • Loading branch information
zargony committed Oct 27, 2024
1 parent c8dff83 commit d7c41e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions firmware/src/json/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ impl<R: BufRead> Reader<R> {
self.expect(b'l').await?;
Ok(())
}

/// Read and discard any remaining data
pub async fn discard_to_end(&mut self) -> Result<(), Error<R::Error>> {
loop {
match self.reader.fill_buf().await?.len() {
0 => break,
len => self.reader.consume(len),
}
}
Ok(())
}
}

impl<R: BufRead> Reader<R> {
Expand Down
5 changes: 5 additions & 0 deletions firmware/src/vereinsflieger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ impl<'a> Connection<'a> {
response.total_articles
);

// Discard remaining body (needed to make the next pipelined request work)
json.discard_to_end()
.await
.map_err(http::Error::MalformedResponse)?;

Ok(())
}
}
Expand Down

0 comments on commit d7c41e0

Please sign in to comment.