Search code examples
phprequestresponsezend-framework3mezzio

How to change or add a header in Zend Expressive


How change or add a header to the response in Zend Expressive 2 (with 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)
    {

    }
}

Solution

  • HtmlResponse, recieves as a third param an array of headers to use at initialization.

    As an example:

    return new HtmlResponse($data, 200, ['Content-Type' => 'application/x-yaml']);