/** * @test */ public function replaceHttpRequestReplacesTheCurrentRequest() { /** @var Request $mockNewHttpRequest */ $mockNewHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock(); $this->componentContext->replaceHttpRequest($mockNewHttpRequest); $this->assertSame($mockNewHttpRequest, $this->componentContext->getHttpRequest()); }
/** * @param ComponentContext $componentContext * @return void * @api */ public function handle(ComponentContext $componentContext) { $request = $componentContext->getHttpRequest(); $trustedRequest = $request->withAttribute(Request::ATTRIBUTE_TRUSTED_PROXY, $this->isFromTrustedProxy($request)); $trustedRequest = $trustedRequest->withAttribute(Request::ATTRIBUTE_CLIENT_IP, $this->getTrustedClientIpAddress($trustedRequest)); $protocolHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_PROTOCOL, $trustedRequest); if ($protocolHeader !== null) { $trustedRequest->getUri()->setScheme($protocolHeader); } $hostHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_HOST, $trustedRequest); if ($hostHeader !== null) { $trustedRequest->getUri()->setHost($hostHeader); } $portHeader = $this->getFirstTrustedProxyHeaderValue(self::HEADER_PORT, $trustedRequest); if ($portHeader !== null) { $trustedRequest->getUri()->setPort($portHeader); } elseif ($protocolHeader !== null) { $trustedRequest->getUri()->setPort(strtolower($protocolHeader) === 'https' ? 443 : 80); } $componentContext->replaceHttpRequest($trustedRequest); }