在部署到服務(wù)器的時(shí)候,通常不想讓別人知道后端程序采用什么語言開發(fā)的,因此請(qǐng)問大家,是否支持去除響應(yīng)標(biāo)頭的Server值,比如TP框架的部署到服務(wù)器上是顯示Apache或者Nginx. 那么webman開發(fā)的還是顯示workerman,是否有方法可以去除或修改。
如果所示:
加個(gè)中間件就行了。 看源碼是判斷有沒有設(shè)置header,沒有header server 就會(huì)拼上這個(gè)
class ApiFormat implements MiddlewareInterface
{
public function process(Request $request, callable $handler): Response
{
/**
* @var Response $response
*/
$response = $handler($request);
$response->header('Server','charles');
return $response;
}
}
然后就會(huì)
修改根目錄下的/support/Response.php
<?php
namespace support;
/**
* Class Response
* @package support
* @link http://www.wtbis.cn/doc/webman/response.html
*/
class Response extends \Webman\Http\Response
{
public function __construct($status = 200, $headers = array(), $body = '')
{
$headers['Server'] = 'nginx';
parent::__construct($status, $headers, $body);
}
}
/support/Response.php這個(gè)文件是webman允許用戶自定義的響應(yīng)類;
它通過config/autoload.php配置,優(yōu)先加載;比用中間件實(shí)現(xiàn)更靠譜。