Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

NotFoundHandler generateTemplatedResponse Content Type missing #647

Open
cgaube opened this issue Nov 18, 2018 · 2 comments
Open

NotFoundHandler generateTemplatedResponse Content Type missing #647

cgaube opened this issue Nov 18, 2018 · 2 comments

Comments

@cgaube
Copy link

cgaube commented Nov 18, 2018

I believe "Content-Type" header is missing from the newly created response object when a 404 error is handled.

/src/Handler/NotFoundHandler.php

/**
     * Generates a response using a template.
     *
     * Template will receive the current request via the "request" variable.
     */
    private function generateTemplatedResponse(
        TemplateRendererInterface $renderer,
        ServerRequestInterface $request
    ) : ResponseInterface {

        $response = ($this->responseFactory)()->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
        $response->getBody()->write(
            $renderer->render($this->template, ['request' => $request, 'layout' => $this->layout])
        );

        return $response;
    }

Should be

/**
     * Generates a response using a template.
     *
     * Template will receive the current request via the "request" variable.
     */
    private function generateTemplatedResponse(
        TemplateRendererInterface $renderer,
        ServerRequestInterface $request
    ) : ResponseInterface {

        $response = ($this->responseFactory)()
                 ->withHeader('Content-Type', 'text/html')
                 ->withStatus(StatusCodeInterface::STATUS_NOT_FOUND);
        $response->getBody()->write(
            $renderer->render($this->template, ['request' => $request, 'layout' => $this->layout])
        );

        return $response;
    }
@plasid

This comment has been minimized.

@weierophinney
Copy link
Member

This repository has been closed and moved to mezzio/mezzio; a new issue has been opened at mezzio/mezzio#5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants