diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2022-09-26 20:27:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 20:27:50 +0200 |
commit | c7dd842f84268985e8701c67a9ea2607c13c9ae1 (patch) | |
tree | 88b55ac6880a539b3f6f8342c388eff6d5cc79ce /ext/fetch/lib.rs | |
parent | 1628dba6db3f9cd5d9730a95f5c06573f66361ca (diff) |
perf(ext/fetch): use content-length in InnerBody.consume (#15925)
This fast path prevents repeated allocations when receiving a fetch body with a known size.
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'ext/fetch/lib.rs')
-rw-r--r-- | ext/fetch/lib.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 20db7abbc..3988acf9e 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -361,6 +361,7 @@ pub struct FetchResponse { headers: Vec<(ByteString, ByteString)>, url: String, response_rid: ResourceId, + content_length: Option<u64>, } #[op] @@ -391,6 +392,8 @@ pub async fn op_fetch_send( res_headers.push((key.as_str().into(), val.as_bytes().into())); } + let content_length = res.content_length(); + let stream: BytesStream = Box::pin(res.bytes_stream().map(|r| { r.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err)) })); @@ -409,6 +412,7 @@ pub async fn op_fetch_send( headers: res_headers, url, response_rid: rid, + content_length, }) } |