summaryrefslogtreecommitdiff
path: root/ext/http/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/http/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/http/lib.rs')
-rw-r--r--ext/http/lib.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index bffe3c3d5..a8c2810bc 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -39,6 +39,8 @@ use flate2::write::GzEncoder;
use flate2::Compression;
use fly_accept_encoding::Encoding;
use hyper::body::Bytes;
+use hyper::body::HttpBody;
+use hyper::body::SizeHint;
use hyper::header::HeaderName;
use hyper::header::HeaderValue;
use hyper::server::conn::Http;
@@ -309,6 +311,7 @@ pub struct HttpStreamResource {
wr: AsyncRefCell<HttpResponseWriter>,
accept_encoding: Encoding,
cancel_handle: CancelHandle,
+ size: SizeHint,
}
impl HttpStreamResource {
@@ -318,11 +321,13 @@ impl HttpStreamResource {
response_tx: oneshot::Sender<Response<Body>>,
accept_encoding: Encoding,
) -> Self {
+ let size = request.body().size_hint();
Self {
conn: conn.clone(),
rd: HttpRequestReader::Headers(request).into(),
wr: HttpResponseWriter::Headers(response_tx).into(),
accept_encoding,
+ size,
cancel_handle: CancelHandle::new(),
}
}
@@ -388,6 +393,10 @@ impl Resource for HttpStreamResource {
fn close(self: Rc<Self>) {
self.cancel_handle.cancel();
}
+
+ fn size_hint(&self) -> (u64, Option<u64>) {
+ (self.size.lower(), self.size.upper())
+ }
}
/// The read half of an HTTP stream.