From f84a2c94ae837a2a78d4357275d7eddb10f884ac Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 6 Nov 2024 10:20:26 +0000 Subject: [PATCH] WIP --- lib/handler/cache-handler.js | 32 ++++++++++++++++++----- lib/handler/cache-revalidation-handler.js | 8 ++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/handler/cache-handler.js b/lib/handler/cache-handler.js index 9a116ffa2d7..d10bf0f017b 100644 --- a/lib/handler/cache-handler.js +++ b/lib/handler/cache-handler.js @@ -48,6 +48,17 @@ class CacheHandler extends DecoratorHandler { this.#handler = handler } + onConnect (abort) { + if (this.#writeStream) { + this.#writeStream.destroy() + this.#writeStream = undefined + } + + if (typeof this.#handler.onConnect === 'function') { + this.#handler.onConnect(abort) + } + } + /** * @see {DispatchHandlers.onHeaders} * @@ -136,13 +147,20 @@ class CacheHandler extends DecoratorHandler { }) if (this.#writeStream) { - this.#writeStream.on('drain', resume) - this.#writeStream.on('error', () => { - // TODO (fix): Make error somehow observable? - this.#writeStream = undefined - // TODO (fix): Should we resume even if was paused downstream? - resume() - }) + const stream = this.#writeStream + this.#writeStream + .on('drain', resume) + .on('error', () => { + // TODO (fix): Make error somehow observable? + }) + .on('close', () => { + if (this.#writeStream === stream) { + this.#writeStream = undefined + } + + // TODO (fix): Should we resume even if was paused downstream? + resume() + }) } } diff --git a/lib/handler/cache-revalidation-handler.js b/lib/handler/cache-revalidation-handler.js index 7589666c4d6..01a809e487e 100644 --- a/lib/handler/cache-revalidation-handler.js +++ b/lib/handler/cache-revalidation-handler.js @@ -42,6 +42,14 @@ class CacheRevalidationHandler extends DecoratorHandler { this.#handler = handler } + onConnect (abort) { + this.#successful = false + + if (typeof this.#handler.onConnect === 'function') { + this.#handler.onConnect(abort) + } + } + /** * @see {DispatchHandlers.onHeaders} *