TYPO3: Send additional HTTP headers from content element

revision 4b75a9b6d11459183ea92f10f1cbac88c2915c26

raw

README.rst

Pretty hacky, but works on TYPO3 v13.

raw

phork0.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
 
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\Utility\GeneralUtility;
 
class Foo
{
    protected function sendRateLimitHeaders(RateLimit $limit): void
    {
        $tsfe = $this->getTsfe();
        $typoscript = $tsfe->getConfigArray();
 
        $headers = $typoscript['additionalHeaders.'] ?? [];
        $headers['910.'] = ['header' => 'X-RateLimit-Remaining: ' . $limit->getRemainingTokens()];
        $headers['911.'] = ['header' => 'X-RateLimit-Retry-After: ' . $limit->getRetryAfter()->getTimestamp() - time()];
        $headers['912.'] = ['header' => 'X-RateLimit-Limit: ' . $limit->getLimit()];
 
 
        $typoscript['additionalHeaders.'] = $headers;
        $tsfe->setConfigArray($typoscript);
    }
 
    protected function getTsfe(): FrontendTypoScript
    {
        return $this->getRequest()->getAttribute('frontend.typoscript');
    }
 
    protected function getRequest(): ServerRequestInterface
    {
        return $GLOBALS['TYPO3_REQUEST'];
    }
 

History