Skip to content

Commit

Permalink
Added completion safety to prevent corking when a Response has been a…
Browse files Browse the repository at this point in the history
…borted
  • Loading branch information
kartikk221 committed Jul 27, 2023
1 parent 561d3f4 commit 08a8a09
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/http/Response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08a8a09

Please sign in to comment.