private function updateHostName(UriInterface $uri)
    {
        if (!$this->options['reuseHostName']) {
            return $uri;
        }
        $params = $this->request->getServerParams();
        $hasPort = !in_array($params['SERVER_PORT'], ['80', '443']);
        if ($hasPort) {
            $uri = $uri->withPort($params['SERVER_PORT']);
        }
        $isSecure = array_key_exists('HTTPS', $params) &&
            $params['HTTPS'] != strtolower('off');
        $scheme =  $isSecure ? 'https' : 'http';
        /** @var UriInterface $uri */
        $uri = $uri->withHost($params['SERVER_NAME']);
        $uri = $uri->withScheme($scheme);
        return $uri;
    }