30 lines
992 B
TypeScript
30 lines
992 B
TypeScript
import {HTTPKernelModule} from '../HTTPKernelModule'
|
|
import {Request} from '../../lifecycle/Request'
|
|
import {Injectable, Inject} from '../../../di'
|
|
import {HTTPKernel} from '../HTTPKernel'
|
|
import {Config} from '../../../service/Config'
|
|
|
|
/**
|
|
* HTTP kernel middleware that sets the `X-Powered-By` header.
|
|
*/
|
|
@Injectable()
|
|
export class PoweredByHeaderInjectionHTTPModule extends HTTPKernelModule {
|
|
public readonly executeWithBlockingWriteback = true
|
|
|
|
@Inject()
|
|
protected readonly config!: Config;
|
|
|
|
public static register(kernel: HTTPKernel): void {
|
|
kernel.register(this).after()
|
|
}
|
|
|
|
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'))
|
|
request.response.setHeader('Server', this.config.get('server.poweredBy.header', 'Extollo'))
|
|
}
|
|
|
|
return request
|
|
}
|
|
}
|