src/Valkyrja/HttpMessage/ServerRequestFactory.php
public static function marshalUriFromServer(array $server, array $headers): Uri
    {
        $uri = new NativeUri();

        // URI scheme
        $scheme = 'http';
        $https  = self::get('HTTPS', $server);

        if (($https && 'off' !== $https)
            || self::getHeader('x-forwarded-proto', $headers, false) === 'https'
        ) {
            $scheme = 'https';
        }

        if (! empty($scheme)) {
            $uri = $uri->withScheme($scheme);
        }

        // Set the host
        $accumulator = (object) ['host' => '', 'port' => null];

        self::marshalHostAndPortFromHeaders($accumulator, $server, $headers);

        $host = $accumulator->host;
        $port = $accumulator->port;

        if (! empty($host)) {
            $uri = $uri->withHost($host);

            if (! empty($port)) {
                $uri = $uri->withPort($port);
            }
        }

        // URI path
        $path = self::marshalRequestUri($server);
        $path = self::stripQueryString($path);

        // URI query
        $query = '';

        if (isset($server['QUERY_STRING'])) {
            $query = ltrim($server['QUERY_STRING'], '?');
        }

        // URI fragment
        $fragment = '';

        if (strpos($path, '#') !== false) {
            [$path, $fragment] = explode('#', $path, 2);
        }

        return $uri
            ->withPath($path)
            ->withFragment($fragment)
            ->withQuery($query);
    }
public static function marshalUriFromServer(array $server, array $headers): Uri
    {
        $uri = new NativeUri();

        // URI scheme
        $scheme = 'http';
        $https  = self::get('HTTPS', $server);

        if (($https && 'off' !== $https)
            || self::getHeader('x-forwarded-proto', $headers, false) === 'https'
        ) {
            $scheme = 'https';
        }

        if (! empty($scheme)) {
            $uri = $uri->withScheme($scheme);
        }

        // Set the host
        $accumulator = (object) ['host' => '', 'port' => null];

        self::marshalHostAndPortFromHeaders($accumulator, $server, $headers);

        $host = $accumulator->host;
        $port = $accumulator->port;

        if (! empty($host)) {
            $uri = $uri->withHost($host);

            if (! empty($port)) {
                $uri = $uri->withPort($port);
            }
        }

        // URI path
        $path = self::marshalRequestUri($server);
        $path = self::stripQueryString($path);

        // URI query
        $query = '';

        if (isset($server['QUERY_STRING'])) {
            $query = ltrim($server['QUERY_STRING'], '?');
        }

        // URI fragment
        $fragment = '';

        if (strpos($path, '#') !== false) {
            [$path, $fragment] = explode('#', $path, 2);
        }

        return $uri
            ->withPath($path)
            ->withFragment($fragment)
            ->withQuery($query);
    }
Marshal the URI from the $_SERVER array and headers.

@param array $server
@param array $headers

@throws \Valkyrja\HttpMessage\Exceptions\InvalidScheme
@throws \Valkyrja\HttpMessage\Exceptions\InvalidQuery
@throws \Valkyrja\HttpMessage\Exceptions\InvalidPort
@throws \Valkyrja\HttpMessage\Exceptions\InvalidPath

@return Uri