lib/src/http/kernel/module/PoweredByHeaderInjectionHTTPModule.ts

30 lines
992 B
TypeScript
Raw Normal View History

2021-06-03 03:36:25 +00:00
import {HTTPKernelModule} from '../HTTPKernelModule'
import {Request} from '../../lifecycle/Request'
import {Injectable, Inject} from '../../../di'
import {HTTPKernel} from '../HTTPKernel'
import {Config} from '../../../service/Config'
2021-03-25 13:50:13 +00:00
/**
* HTTP kernel middleware that sets the `X-Powered-By` header.
*/
@Injectable()
export class PoweredByHeaderInjectionHTTPModule extends HTTPKernelModule {
2021-03-09 15:42:19 +00:00
public readonly executeWithBlockingWriteback = true
@Inject()
protected readonly config!: Config;
2021-06-03 03:36:25 +00:00
public static register(kernel: HTTPKernel): void {
kernel.register(this).after()
}
2021-06-03 03:36:25 +00:00
public async apply(request: Request): Promise<Request> {
if ( !this.config.get('server.poweredBy.hide', false) ) {
request.response.setHeader('X-Powered-By', this.config.get('server.poweredBy.header', 'Extollo'))
2021-07-17 17:49:07 +00:00
request.response.setHeader('Server', this.config.get('server.poweredBy.header', 'Extollo'))
}
return request
}
}