summaryrefslogtreecommitdiff
path: root/ext/fetch/lib.rs
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2022-10-04 15:48:50 +0200
committerGitHub <noreply@github.com>2022-10-04 15:48:50 +0200
commit569287b15b6482a39f2c816f103574c3b35351f8 (patch)
treeff8433fc87613e3016ff7a188ee34aa3fc7d81c4 /ext/fetch/lib.rs
parent0b4a6c4d084df54e827bc7767ce8653e06c45e93 (diff)
perf(ext/fetch): consume body using ops (#16038)
This commit adds a fast path to `Request` and `Response` that make consuming request bodies much faster when using `Body#text`, `Body#arrayBuffer`, and `Body#blob`, if the body is a FastStream. Because the response bodies for `fetch` are FastStream, this speeds up consuming `fetch` response bodies significantly.
Diffstat (limited to 'ext/fetch/lib.rs')
-rw-r--r--ext/fetch/lib.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs
index a7daaa63a..0adc32343 100644
--- a/ext/fetch/lib.rs
+++ b/ext/fetch/lib.rs
@@ -408,6 +408,7 @@ pub async fn op_fetch_send(
.add(FetchResponseBodyResource {
reader: AsyncRefCell::new(stream_reader),
cancel: CancelHandle::default(),
+ size: content_length,
});
Ok(FetchResponse {
@@ -479,6 +480,7 @@ type BytesStream =
struct FetchResponseBodyResource {
reader: AsyncRefCell<StreamReader<BytesStream, bytes::Bytes>>,
cancel: CancelHandle,
+ size: Option<u64>,
}
impl Resource for FetchResponseBodyResource {
@@ -498,6 +500,10 @@ impl Resource for FetchResponseBodyResource {
})
}
+ fn size_hint(&self) -> (u64, Option<u64>) {
+ (0, self.size)
+ }
+
fn close(self: Rc<Self>) {
self.cancel.cancel()
}