protected function getForwardedIp(ServerRequestInterface $request, $ip)
    {
        $ips = [$ip];
        
        $forwardedFor = $this->splitIps($request->getHeaderLine('X-Forwarded-For'));
        $forwarded = $this->extractForFromForwardedHeader($request->getHeaderLine('Forwarded'));
        $clientIp = $this->splitIps($request->getHeaderLine('Client-Ip'));
        
        if (!$this->areAllTheSame($forwardedFor, $forwarded, $clientIp)) {
            $msg = 'Only one of `X-Forwarded-For`, `Forwarded` or `Client-Ip` headers should be set';
            throw new \RuntimeException($msg);
        }
        
        $fwd = $forwardedFor ?: $forwarded ?: $clientIp;
        
        if ($fwd) {
            $ips = array_merge($ips, $fwd);
        }
        
        return $this->getTrustedForwardedIp($ips);
    }