From 2da714aab69d7737aa4508d2bf444a63ae11caf8 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Sat, 9 Sep 2017 19:42:29 +0200 Subject: [PATCH] [FEATURE] Add frontend debug output as HTTP Response Header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current debug information in the frontend is added as HTML comment, but breaks non-HTML pages (e.g. JSON output). The debug information (= parse time of the frontend request) is now sent as HTTP Response Header found at "X-TYPO3-Parsetime". Resolves: #82419 Releases: master Change-Id: Ibd84825fd3ebdcb1c88e0059d00d78b4bb20f53e Reviewed-on: https://review.typo3.org/54075 Reviewed-by: Andreas Fernandez <typo3@scripting-base.de> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Markus Hölzle <typo3@markus-hoelzle.de> Tested-by: Markus Hölzle <typo3@markus-hoelzle.de> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> --- .../DefaultConfigurationDescription.yaml | 2 +- ...ndDebugInformationAsHTTPResponseHeader.rst | 25 +++++++++++++++++++ .../frontend/Classes/Http/RequestHandler.php | 18 +++++++------ 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-82419-SendFrontendDebugInformationAsHTTPResponseHeader.rst diff --git a/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml b/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml index d90d8ec43751..393f7b3841da 100644 --- a/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml +++ b/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml @@ -381,7 +381,7 @@ FE: description: 'Additional relative paths (comma-list) to allow TypoScript resources be in. Should be prepended with ''/''. If not, then any path where the first part is like this path will match. That is: ''myfolder/ , myarchive'' will match eg. ''myfolder/'', ''myarchive/'', ''myarchive_one/'', ''myarchive_2/'' ... No check is done to see if this directory actually exists in the root of the site. Paths are matched by simply checking if these strings equals the first part of any TypoScript resource filepath. (See class template, function init() in <code>\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser)</code>' debug: type: bool - description: 'If enabled, additional information (if the page was cached, and how long the processing took) as HTML comments is rendered at the end of each frontend request. This can also be enabled/disabled via the TypoScript option <code>config.debug = 0</code>.' + description: 'If enabled, the total parsetime of the page is added as HTTP response header "X-TYPO3-Parsetime". This can also be enabled/disabled via the TypoScript option <code>config.debug = 0</code>.' compressionLevel: type: int description: 'Determines output compression of FE output. Makes output smaller but slows down the page generation depending on the compression level. Requires zlib in your PHP installation. Range 1-9, where 1 is least compression and 9 is greatest compression. ''true'' as value will set the compression based on the PHP default settings (usually 5). Suggested and most optimal value is 5.' diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-82419-SendFrontendDebugInformationAsHTTPResponseHeader.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-82419-SendFrontendDebugInformationAsHTTPResponseHeader.rst new file mode 100644 index 000000000000..bde581ae06f4 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-82419-SendFrontendDebugInformationAsHTTPResponseHeader.rst @@ -0,0 +1,25 @@ +.. include:: ../../Includes.txt + +========================================================================= +Feature: #82419 - Send Frontend Debug Information as HTTP Response Header +========================================================================= + +See :issue:`82419` + +Description +=========== + +When setting `config.debug=1` or `$TYPO3_CONF_VARS[FE][debug]` the parse time is now sent as HTTP +response header "X-TYPO3-Parsetime" instead of HTML comments. + + +Impact +====== + +This ensures that non-HTML-content (e.g. JSON output) does not break when having debugging for the +Frontend enabled. + +If you look for the parse time of a frontend request, this can now easily be shown via +`curl -I https://mydomain.com` or in the developer toolbar of the browser. + +.. index:: Frontend \ No newline at end of file diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php index 7215158f9fea..58c4051078b4 100644 --- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php +++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php @@ -229,16 +229,22 @@ class RequestHandler implements RequestHandlerInterface } // Store session data for fe_users $this->controller->storeSessionData(); + + // Create a Response object when sending content + if ($sendTSFEContent) { + $response = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\Response::class); + } + // Statistics $GLOBALS['TYPO3_MISC']['microtime_end'] = microtime(true); - if ($this->controller->isOutputting()) { + if ($sendTSFEContent) { if (isset($this->controller->config['config']['debug'])) { - $debugParseTime = (bool)$this->controller->config['config']['debug']; + $includeParseTime = (bool)$this->controller->config['config']['debug']; } else { - $debugParseTime = !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['debug']); + $includeParseTime = !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['debug']); } - if ($debugParseTime) { - $this->controller->content .= LF . '<!-- Parsetime: ' . $this->timeTracker->getParseTime() . 'ms -->'; + if ($includeParseTime) { + $response = $response->withHeader('X-TYPO3-Parsetime', $this->timeTracker->getParseTime() . 'ms'); } } $this->controller->redirectToExternalUrl(); @@ -257,8 +263,6 @@ class RequestHandler implements RequestHandlerInterface } if ($sendTSFEContent) { - /** @var \TYPO3\CMS\Core\Http\Response $response */ - $response = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\Response::class); $response->getBody()->write($this->controller->content); } GeneralUtility::devLog('END of FRONTEND session', 'cms', 0, ['_FLUSH' => true]); -- GitLab