From 08a8a099416edeb2e1783c3971581f8792223f8e Mon Sep 17 00:00:00 2001 From: kartikk221 Date: Thu, 27 Jul 2023 00:18:43 -0400 Subject: [PATCH] Added completion safety to prevent corking when a Response has been aborted --- src/components/http/Response.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/http/Response.js b/src/components/http/Response.js index 5d5d318..b3302fa 100644 --- a/src/components/http/Response.js +++ b/src/components/http/Response.js @@ -485,14 +485,14 @@ class Response { * @returns {Response} */ send(body, close_connection) { - // If the response has not been corked yet, cork it and wait for the next tick to send the response - if (this._cork && !this.#corked) { - this.#corked = true; - return this.#raw_response.cork(() => this.send(body, close_connection)); - } - // Ensure response connection is still active if (!this.completed) { + // If the response has not been corked yet, cork it and wait for the next tick to send the response + if (this._cork && !this.#corked) { + this.#corked = true; + return this.#raw_response.cork(() => this.send(body, close_connection)); + } + // Attempt to initiate the response to ensure status code & headers get written first if (this._initiate_response()) { // Stop downloading further body chunks as we are done with the response