Add support for middleware

This commit is contained in:
2021-03-09 09:42:19 -06:00
parent 2868ca1910
commit 4f23ac7156
19 changed files with 319 additions and 31 deletions

View File

@@ -20,6 +20,7 @@ export class Response {
private _sentHeaders: boolean = false
private _responseEnded: boolean = false
private _status: HTTPStatus = HTTPStatus.OK
private _blockingWriteback: boolean = false
public body: string = ''
public readonly sending$: BehaviorSubject<Response> = new BehaviorSubject<Response>()
public readonly sent$: BehaviorSubject<Response> = new BehaviorSubject<Response>()
@@ -88,6 +89,18 @@ export class Response {
return this._sentHeaders
}
public hasBody() {
return !!this.body
}
public blockingWriteback(set?: boolean) {
if ( typeof set !== 'undefined' ) {
this._blockingWriteback = set
}
return this._blockingWriteback
}
public async write(data: any) {
return new Promise<void>((res, rej) => {
if ( !this._sentHeaders ) this.sendHeaders()