|
|
|
import {Injectable} from "../../di";
|
|
|
|
import {AppClass} from "../../lifecycle/AppClass";
|
|
|
|
import {HTTPKernel} from "./HTTPKernel";
|
|
|
|
import {Request} from "../lifecycle/Request";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for modules that define logic that is applied to requests
|
|
|
|
* handled by the HTTP kernel.
|
|
|
|
*/
|
|
|
|
@Injectable()
|
|
|
|
export class HTTPKernelModule extends AppClass {
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
public readonly executeWithBlockingWriteback: boolean = false
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given module should be applied to the incoming request.
|
|
|
|
* @param {Request} request
|
|
|
|
* @return Promise<boolean>
|
|
|
|
*/
|
|
|
|
public async match(request: Request): Promise<boolean> {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public static register(kernel: HTTPKernel) {
|
|
|
|
kernel.register(this).before()
|
|
|
|
}
|
|
|
|
}
|