Add better detection for write-after-destroy errors on the response
This commit is contained in:
@@ -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<void> {
|
||||
return new Promise<void>((res, rej) => {
|
||||
if ( this.responseEnded ) {
|
||||
if ( this.responseEnded || this.serverResponse.destroyed ) {
|
||||
throw new ErrorWithContext('Tried to write to Response after lifecycle ended.')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user