}
}
+#[throws(AE)]
+pub async fn read_limited_body<S,E>(limit: usize, mut stream: S) -> Box<[u8]>
+where S: futures::Stream<Item=Result<hyper::body::Bytes,E>> + Unpin,
+ // we also require that the Stream is cancellation-safe
+ E: std::error::Error + Sync + Send + 'static,
+{
+ let mut accum = vec![];
+ while let Some(item) = stream.next().await {
+ let b = item.context("HTTP error fetching response body")?;
+ if accum.len() + b.len() > limit {
+ throw!(anyhow!("maximum response body size {} exceeded", limit));
+ }
+ accum.extend(b);
+ }
+ accum.into()
+}
+
use sha2::Digest as _;
type HmacH = sha2::Sha256;