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} *