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-07 02:58:48 +00:00
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* HTTP kernel middleware that sets the `X-Powered-By` header.
|
|
|
|
*/
|
2021-03-07 18:51:04 +00:00
|
|
|
@Injectable()
|
|
|
|
export class PoweredByHeaderInjectionHTTPModule extends HTTPKernelModule {
|
2021-03-09 15:42:19 +00:00
|
|
|
public readonly executeWithBlockingWriteback = true
|
|
|
|
|
2021-03-08 15:00:43 +00:00
|
|
|
@Inject()
|
|
|
|
protected readonly config!: Config;
|
|
|
|
|
2021-06-03 03:36:25 +00:00
|
|
|
public static register(kernel: HTTPKernel): void {
|
2021-03-07 18:51:04 +00:00
|
|
|
kernel.register(this).after()
|
2021-03-07 02:58:48 +00:00
|
|
|
}
|
|
|
|
|
2021-06-03 03:36:25 +00:00
|
|
|
public async apply(request: Request): Promise<Request> {
|
2021-03-08 15:00:43 +00:00
|
|
|
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'))
|
2021-03-08 15:00:43 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 02:58:48 +00:00
|
|
|
return request
|
|
|
|
}
|
|
|
|
}
|