From 7d8a8a04614cd3a9ef57569505ae6eb728869ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 28 May 2024 21:46:04 +0100 Subject: fix(ext/http): flush gzip streaming response (#23991) This commit changes `gzip` compression in `Deno.serve` API to flush data after each write. There's a slight performance regression, but provided test shows a scenario that was not possible before. --------- Co-authored-by: Divy Srivastava --- ext/http/response_body.rs | 2 +- ext/node/polyfills/http.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'ext') diff --git a/ext/http/response_body.rs b/ext/http/response_body.rs index fd1203f53..3c25265d7 100644 --- a/ext/http/response_body.rs +++ b/ext/http/response_body.rs @@ -394,7 +394,7 @@ impl PollFrame for GZipResponseStream { stm.compress(&[], &mut buf, flate2::FlushCompress::Finish) } ResponseStreamResult::NonEmptyBuf(mut input) => { - let res = stm.compress(&input, &mut buf, flate2::FlushCompress::None); + let res = stm.compress(&input, &mut buf, flate2::FlushCompress::Sync); let len_in = (stm.total_in() - start_in) as usize; debug_assert!(len_in <= input.len()); this.crc.update(&input[..len_in]); diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 6b862ce83..ec3fe6e0b 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -671,6 +671,9 @@ class ClientRequest extends OutgoingMessage { (async () => { try { const res = await op_fetch_send(this._req.requestRid); + if (this._req.cancelHandleRid !== null) { + core.tryClose(this._req.cancelHandleRid); + } try { cb?.(); } catch (_) { @@ -709,10 +712,6 @@ class ClientRequest extends OutgoingMessage { Object.entries(res.headers).flat().length, ); - if (this._req.cancelHandleRid !== null) { - core.tryClose(this._req.cancelHandleRid); - } - if (incoming.upgrade) { if (this.listenerCount("upgrade") === 0) { // No listeners, so we got nothing to do -- cgit v1.2.3