Project

General

Profile

Actions

Bug #96294

open

PageContentErrorHandler ignores configured additionalHeaders

Added by Marc Willmann almost 3 years ago. Updated almost 2 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-12-08
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

When using a page e.g. as 404 error page the in TypoScript configured additionalHeaders are ignored and not set. Most likely these headers are lost when fetching the internal error page via HTTP and deliver the result to the client.

This behaviour was detected in TYPO3 10LTS, but is the very same in 11LTS.

TS:

page.config.additionalHeaders.10.header = X-Powered-By: nothing

works fine on every page, except the error pages.


Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Bug #105591: ext:felogin does not delete fe_typo_user Cookie on logoutNewTorben Hansen2024-11-13

Actions
Actions #1

Updated by Christian Kuhn almost 3 years ago

Interesting. Is this gone in v11 when you enable 'Subrequest page errors' feature toggle? This may not work out if extensions are not sub request ready (which will be enforced in v12), but it could be a start.

Actions #2

Updated by Rafael Kähm almost 2 years ago

The source of trouble is in PageContentErrorHandler, which delegates the "content-type" header only.

See: https://github.com/TYPO3/typo3/blob/fc51ccbf2bb8a8c959aa74cbceca124971e6e7fd/typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php#L122

Would propose to delegate all headers from sub-request response.

There is the temporary solution:

<?php

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

namespace ......\PageErrorHandler;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler;

/**
 * Class PageNotFoundHandler, extends core functionality of {@link PageContentErrorHandler}.
 * It reuses the headers of response on sub-request.
 * 
 * NOTE: Can be removed if https://forge.typo3.org/issues/96294 is solved.
 */
class PageNotFoundHandler extends PageContentErrorHandler
{
    /**
     * @var ResponseInterface|null
     */
    protected ?ResponseInterface $responseOfSubRequest = null;

    public function handlePageError(ServerRequestInterface $request, string $message, array $reasons = []): ResponseInterface
    {
        $response = parent::handlePageError($request, $message, $reasons);
        if ($this->responseOfSubRequest instanceof ResponseInterface) {
            foreach ($this->responseOfSubRequest->getHeaders() as $headerName => $headerValue) {
                $response = $response->withHeader($headerName, $headerValue);
            }
        }
        return $response;
    }

    /**
     * @inheritDoc
     */
    protected function stashEnvironment(callable $fetcher): ResponseInterface
    {
        $this->responseOfSubRequest = parent::stashEnvironment($fetcher);
        return $this->responseOfSubRequest;
    }
}
Actions #3

Updated by Benni Mack 9 days ago

  • Related to Bug #105591: ext:felogin does not delete fe_typo_user Cookie on logout added
Actions

Also available in: Atom PDF