Use RocList::from_iter in sendRequest

This commit is contained in:
Brian Carroll 2022-07-18 21:01:04 +01:00
parent d55d1b00d9
commit a2b130a3c3
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0

View file

@ -145,21 +145,13 @@ pub extern "C" fn roc_fx_sendRequest(roc_request: &glue::Request) -> glue::Respo
.map(|val| val.max(BODY_MAX_BYTES))
.unwrap_or(BODY_MAX_BYTES);
let mut bytes: Vec<u8> = Vec::with_capacity(len);
match response
let bytes_iter = response
.into_reader()
.take(len as u64)
.read_to_end(&mut bytes)
{
Ok(_read_bytes) => {}
Err(_) => {
// Not totally accurate, but let's deal with this later when we do async
return glue::Response::NetworkError;
}
}
.bytes()
.take(len)
.filter_map(|result| result.ok());
// Note: we could skip a full memcpy if we had `RocList::from_iter`.
let body = RocList::from_slice(&bytes);
let body: RocList<u8> = RocList::from_iter(bytes_iter);
let metadata = Metadata {
headers: RocList::empty(), // TODO