Make HTTPServer ignore responses that cannot be sent

This commit is contained in:
Garrett Mills 2022-03-30 22:19:33 -05:00
parent 3d7d583367
commit 514a578260
3 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@extollo/lib", "name": "@extollo/lib",
"version": "0.9.14", "version": "0.9.15",
"description": "The framework library that lifts up your code.", "description": "The framework library that lifts up your code.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@ -255,6 +255,14 @@ export class Response {
await this.sent$.next(this) await this.sent$.next(this)
} }
/**
* Returns true if the response can still be sent. False if it has been sent
* or the connection has been destroyed.
*/
public canSend(): boolean {
return !(this.responseEnded || this.serverResponse.destroyed)
}
/** /**
* Mark the response as ended and close the socket. * Mark the response as ended and close the socket.
*/ */

View File

@ -128,7 +128,9 @@ export class HTTPServer extends Unit {
await error(new ErrorWithContext('Unknown error occurred.', { e })) await error(new ErrorWithContext('Unknown error occurred.', { e }))
} }
await extolloReq.response.send() if ( extolloReq.response.canSend() ) {
await extolloReq.response.send()
}
}) })
} }
} }