From 795adac68b98a4a22af8516d24de6cdd5e584d54 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Wed, 30 Mar 2022 18:33:37 -0500 Subject: [PATCH] Add better detection for write-after-destroy errors on the response --- package.json | 2 +- src/http/lifecycle/Response.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fb14b69..c70112d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.9.10", + "version": "0.9.11", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/http/lifecycle/Response.ts b/src/http/lifecycle/Response.ts index f0e35ab..52ee2b1 100644 --- a/src/http/lifecycle/Response.ts +++ b/src/http/lifecycle/Response.ts @@ -3,6 +3,7 @@ import {ErrorWithContext, HTTPStatus, BehaviorSubject} from '../../util' import {ServerResponse} from 'http' import {HTTPCookieJar} from '../kernel/HTTPCookieJar' import {Readable} from 'stream' +import {Logging} from '../../service/Logging' /** * Error thrown when the server tries to re-send headers after they have been sent once. @@ -68,6 +69,10 @@ export class Response { protected readonly serverResponse: ServerResponse, ) { } + protected get logging(): Logging { + return this.request.make(Logging) + } + /** Get the currently set response status. */ public getStatus(): HTTPStatus { return this.status @@ -195,7 +200,7 @@ export class Response { */ public async write(data: string | Buffer | Uint8Array | Readable): Promise { return new Promise((res, rej) => { - if ( this.responseEnded ) { + if ( this.responseEnded || this.serverResponse.destroyed ) { throw new ErrorWithContext('Tried to write to Response after lifecycle ended.') }