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

@@ -58,18 +58,30 @@ export class HTTPKernel extends AppClass {
public async handle(request: Request): Promise<Request> {
try {
for (const module of this.preflight.toArray()) {
this.logging.verbose(`Applying pre-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
if ( !request.response.blockingWriteback() || module.executeWithBlockingWriteback ) {
this.logging.verbose(`Applying pre-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
} else {
this.logging.verbose(`Skipping pre-flight HTTP kernel module because of blocking write-back: ${module.constructor.name}`)
}
}
if (this.inflight) {
this.logging.verbose(`Applying core HTTP kernel module: ${this.inflight.constructor.name}`)
request = await this.inflight.apply(request)
if ( !request.response.blockingWriteback() || this.inflight.executeWithBlockingWriteback ) {
this.logging.verbose(`Applying core HTTP kernel module: ${this.inflight.constructor.name}`)
request = await this.inflight.apply(request)
} else {
this.logging.verbose(`Skipping core HTTP kernel module because of blocking write-back: ${this.inflight.constructor.name}`)
}
}
for (const module of this.postflight.toArray()) {
this.logging.verbose(`Applying post-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
if ( !request.response.blockingWriteback() || module.executeWithBlockingWriteback ) {
this.logging.verbose(`Applying post-flight HTTP kernel module: ${module.constructor.name}`)
request = await module.apply(request)
} else {
this.logging.verbose(`Skipping post-flight HTTP kernel module because of blocking write-back: ${module.constructor.name}`)
}
}
} catch (e: any) {
this.logging.error(e)