let mut resp = resp.into_body();
let max_body = c.ic.max_batch_down.sat() + MAX_OVERHEAD;
let resp = read_limited_bytes(max_body, &mut resp).await
- .context("fetching response body")?;
+ .discard_data().context("fetching response body")?;
if ! status.is_success() {
throw!(anyhow!("HTTP error status={} body={:?}",
Hyper(#[from] hyper::Error),
}
+impl ReadLimitedError {
+ pub fn discard_data(&mut self) { match self {
+ ReadLimitedError::Truncated { sofar,.. } => { mem::take(sofar); },
+ _ => { },
+ } }
+}
+#[ext(pub)]
+impl<T> Result<T,ReadLimitedError> {
+ fn discard_data(self) -> Self {
+ self.map_err(|mut e| { e.discard_data(); e })
+ }
+}
+
#[throws(ReadLimitedError)]
pub async fn read_limited_bytes<S>(limit: usize, stream: &mut S) -> Box<[u8]>
where S: futures::Stream<Item=Result<hyper::body::Bytes,hyper::Error>>