Feature: #83736 - Extended PSR-7 requests with TYPO3 normalized server parameters

See forge#83736


The PSR-7 based ServerRequest objects created by TYPO3 now contain a TYPO3-specific attribute object for normalized server parameters that for instance resolves variables if the instance is behind a reverse proxy. This substitutes GeneralUtility::getIndpEnv().

The object is for now available from ServerRequestInterface $request objects as attribute. The request object is given to controllers, example:

$normalizedParams = $request->getAttribute('normalizedParams');
$requestPort = $normalizedParams->getRequestPort();

The request object is also available as a global variable in $GLOBALS['TYPO3_REQUEST']. This is a workaround for the core which has to access the server parameters at places where $request is not available. So, while this object is globally available during any HTTP request, it is considered bad practice to use it. The global object will vanish later if the core code has been refactored enough to not rely on it anymore.

For now, class NormalizedParams is a one-to-one transition of GeneralUtility::getIndpEnv(), the old arguments can be substituted with these calls:

  • SCRIPT_NAME is now ->getScriptName()
  • SCRIPT_FILENAME is now ->getScriptFilename()
  • REQUEST_URI is now ->getRequestUri()
  • TYPO3_REV_PROXY is now ->isBehindReverseProxy()
  • REMOTE_ADDR is now ->getRemoteAddress()
  • HTTP_HOST is now ->getHttpHost()
  • TYPO3_DOCUMENT_ROOT is now ->getDocumentRoot()
  • TYPO3_HOST_ONLY is now ->getRequestHostOnly()
  • TYPO3_PORT is now ->getRequestPort()
  • TYPO3_REQUEST_HOST is now ->getRequestHost()
  • TYPO3_REQUEST_URL is now ->getRequestUrl()
  • TYPO3_REQUEST_SCRIPT is now ->getRequestScript()
  • TYPO3_REQUEST_DIR is now ->getRequestDir()
  • TYPO3_SITE_URL is now ->getSiteUrl()
  • TYPO3_SITE_PATH is now ->getSitePath()
  • TYPO3_SITE_SCRIPT is now ->getSiteScript()
  • TYPO3_SSL is now ->isHttps()

Some further old getIndpEnv() arguments directly access $request->serverParams() and do not apply any normalization. These have been transferred to the new class, too, but will be deprecated later if the core does not use these anymore:

  • PATH_INFO is now ->getPathInfo(), but better use ->getScriptName() instead
  • HTTP_REFERER is now ->getHttpReferer(), but better use $request->getServerParams()['HTTP_REFERER'] instead
  • HTTP_USER_AGENT is now ->getHttpUserAgent(), but better use $request->getServerParams()['HTTP_USER_AGENT'] instead
  • HTTP_ACCEPT_ENCODING is now ->getHttpAcceptEncoding(), but better use $request->getServerParams()['HTTP_ACCEPT_ENCODING'] instead
  • HTTP_ACCEPT_LANGUAGE is now ->getHttpAcceptLanguage(), but better use $request->getServerParams()['HTTP_ACCEPT_LANGUAGE'] instead
  • REMOTE_HOST is now ->getRemoteHost(), but better use $request->getServerParams()['REMOTE_HOST'] instead
  • QUERY_STRING is now ->getQueryString(), but better use $request->getServerParams()['QUERY_STRING'] instead


The PSR-7 request objects created by TYPO3 now contain an instance of NormalizedParams which can be used instead of GeneralUtility::getIndpEnv() to access normalized server params.