lib/src/http/kernel/HTTPKernelModule.ts

47 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-06-03 03:36:25 +00:00
import {Injectable} from '../../di'
import {AppClass} from '../../lifecycle/AppClass'
import {HTTPKernel} from './HTTPKernel'
import {Request} from '../lifecycle/Request'
2021-03-25 13:50:13 +00:00
/**
* Base class for modules that define logic that is applied to requests
* handled by the HTTP kernel.
*/
@Injectable()
export class HTTPKernelModule extends AppClass {
2021-03-25 13:50:13 +00:00
/**
* By default, if a kernel module interrupts the request flow to send a response
* (for example, if an error occurs), subsequent modules are skipped.
*
* However, a module can override this property to be true and its logic will still
* be applied, even after a module has interrupted the request flow.
*/
2021-03-09 15:42:19 +00:00
public readonly executeWithBlockingWriteback: boolean = false
/**
* Returns true if the given module should be applied to the incoming request.
* @param {Request} request
* @return Promise<boolean>
*/
2021-06-03 03:36:25 +00:00
public async match(request: Request): Promise<boolean> { // eslint-disable-line @typescript-eslint/no-unused-vars
return true
}
/**
* Apply the module to the incoming request.
* @param {Request} request
* @return Promise<Request>
*/
public async apply(request: Request): Promise<Request> {
return request
}
/**
* Register this module with the given HTTP kernel.
* @param {HTTPKernel} kernel
*/
2021-06-03 03:36:25 +00:00
public static register(kernel: HTTPKernel): void {
kernel.register(this).before()
}
}