如何在Zend Expressive 2中使用HtmlResponse更改或添加标题?
class NotModifiedMiddleware implements ServerMiddlewareInterface
{
/**
* Process an incoming server request and return a response, optionally delegating
* to the next middleware component to create the response.
*
* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
*
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
}
}
答案 0 :(得分:1)
这很容易。
您只需让代理处理请求并获得回复,例如:
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
$response = $delegate->process($request);
$now = new \DateTime();
return $response->withHeader('Last-Modified', $now->format('c'));
}
答案 1 :(得分:1)
HtmlResponse,将在初始化时使用的标头数组作为第三个参数。
例如:
return new HtmlResponse($data, 200, ['Content-Type' => 'application/x-yaml']);