diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-05-28 21:46:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-28 22:46:04 +0200 |
| commit | 7d8a8a04614cd3a9ef57569505ae6eb728869ecd (patch) | |
| tree | f5349b834879684d9cb54459018dd93dac9a602d /ext | |
| parent | 69da5d8290fda4797af5e3b3e5e7bf3c0141f203 (diff) | |
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 <dj.srivastava23@gmail.com>
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/http/response_body.rs | 2 | ||||
| -rw-r--r-- | ext/node/polyfills/http.ts | 7 |
2 files changed, 4 insertions, 5 deletions
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 |
