summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
c61b3bd)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
let status = resp.status();
let mut resp = resp.into_body();
let max_body = c.ic.max_batch_down.sat() + MAX_OVERHEAD;
let status = resp.status();
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
+ let resp = read_limited_bytes(max_body, default(), &mut resp).await
.discard_data().context("fetching response body")?;
if ! status.is_success() {
.discard_data().context("fetching response body")?;
if ! status.is_success() {
};
let mut body = req.into_body();
};
let mut body = req.into_body();
- let initial = match read_limited_bytes(METADATA_MAX_LEN, &mut body).await {
+ let initial = match read_limited_bytes(
+ METADATA_MAX_LEN, default(), &mut body
+ ).await {
Ok(all) => all,
Err(ReadLimitedError::Truncated { sofar,.. }) => sofar,
Err(ReadLimitedError::Hyper(e)) => throw!(e),
Ok(all) => all,
Err(ReadLimitedError::Truncated { sofar,.. }) => sofar,
Err(ReadLimitedError::Hyper(e)) => throw!(e),
}
#[throws(ReadLimitedError)]
}
#[throws(ReadLimitedError)]
-pub async fn read_limited_bytes<S>(limit: usize, stream: &mut S) -> Box<[u8]>
+pub async fn read_limited_bytes<S>(limit: usize, initial: Box<[u8]>,
+ stream: &mut S) -> Box<[u8]>
where S: futures::Stream<Item=Result<hyper::body::Bytes,hyper::Error>>
+ Debug + Unpin,
// we also require that the Stream is cancellation-safe
{
where S: futures::Stream<Item=Result<hyper::body::Bytes,hyper::Error>>
+ Debug + Unpin,
// we also require that the Stream is cancellation-safe
{
- let mut accum = vec![];
+ let mut accum = initial.into_vec();
while let Some(item) = stream.next().await {
let b = item?;
accum.extend(b);
while let Some(item) = stream.next().await {
let b = item?;
accum.extend(b);