未授权请求

@param  string $uri
@param  string $protocol

@return self 401
544323
public static function unauthorized(string $uri, string $protocol = Protocol::HTTP): self
    {
        return new static(sprintf('Unauthorized: `%s`', $uri), $protocol, 401);
    }
542527
private static function obfuscateUri($uri)
    {
        $userInfo = $uri->getUserInfo();

        if (false !== ($pos = strpos($userInfo, ':'))) {
            return $uri->withUserInfo(substr($userInfo, 0, $pos), '***');
        }

        return $uri;
    }
597073
function setProtocol($protocol)
    {
        $protocol = (string) $protocol;
        $protocol = strtolower($protocol);
        
        if ($protocol !== 'http' && $protocol !== 'https')
            throw new \InvalidArgumentException(sprintf(
                'Protocol (%s) not supported; using "http" or "https".'
                , $protocol
            ));
        
        $this->protocol = $protocol;
        return $this;
    }
593338
function redirectTo( $uri )
    {
        $originalURI = $uri;
        $uri = preg_replace( "#(^.*)(/+)$#", "\$1", $uri );
        if ( strlen( $originalURI ) != 0 and
             strlen( $uri ) == 0 )
            $uri = '/';

        $urlComponents = parse_url( $uri );
        // eZSys::hostname() can contain port if present.
        // So parsing it with parse_url() as well to only get host.
        $currentHostname = eZSys::hostname();
        $currentHostnameParsed = parse_url( $currentHostname, PHP_URL_HOST );
        $currentHostname = $currentHostnameParsed ? $currentHostnameParsed : $currentHostname;
        if ( isset( $urlComponents['host'] ) && $urlComponents['host'] !== $currentHostname )
        {
            $allowedHosts = $this->getAllowedRedirectHosts();
            if ( !isset( $allowedHosts[$urlComponents['host']] ) )
            {
                // Non-authorized host, return only the URI (without host) + query string and fragment if present.
                eZDebug::writeError( "Redirection requested on non-authorized host '{$urlComponents['host']}'" );
                header( $_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden' );
                echo "Redirection requested on non-authorized host";
                eZDB::checkTransactionCounter();
                eZExecution::cleanExit();
            }
        }

        $this->RedirectURI = $uri;
        $this->setExitStatus( self::STATUS_REDIRECT );
    }
884176
public function createRequest($method, $uri)
    {
        if (is_string($uri)) {
            $uri = (new UriFactory())->createUri($uri);
        }
        return new Request($method, $uri);
    }
787131
public function addURIScheme(string $url = '', string $protocol = 'http'): string
    {
        $scheme = $protocol.'://';

        if ('' !== $url && false === System::getContainer()->get('huh.utils.string')->startsWith($url, $protocol)) {
            $url = $scheme.$url;
        }

        return $url;
    }
92526
public static function unregister($protocol = null)
    {
        $protocol = $protocol ?: self::DEFAULT_PROTOCOL;
        stream_wrapper_unregister($protocol);
        unset(self::$clients[$protocol]);
    }
27475
public function post($uri, $parameters = array())
    {
        return $this->request(self::METHOD_POST, $this->getUrl($uri), $parameters);
    }
852915
public function unregisterStream($protocol)
    {
        if (isset(self::$streams[$protocol])) {
            $result = stream_wrapper_unregister($protocol);
            if ($result === true) {
                unset(self::$streams[$protocol]);
            }
        }

        return $this;
    }
615284
public static function createServerRequest($method, $uri)
    {
        if (! static::$serverRequestFactory) {
            static::$serverRequestFactory = new ServerRequestFactory();
        }

        return static::$serverRequestFactory->createServerRequest($method, $uri);
    }
1069341
public function setUri($uri=''){
    $this->uri = $uri;
    // 解析uri
    $uriObj = DdvUrl::parse($uri);
    empty($uriObj['host']) || $this->setHost($uriObj['host']);
    empty($uriObj['path']) || $this->setPath($uriObj['path']);
    empty($uriObj['query']) || $this->setQuery($uriObj['query']);
    empty($uriObj['port']) || $this->setPort($uriObj['port']);
    empty($uriObj['fragment']) || $this->setFragment($uriObj['fragment']);
    return $this;
  }
145906
public static function token(String $uri = NULL, String $type = 'post')
    {
        Security::CSRFToken($uri, $type);
    }
465081
public static function badRequest(string $message, string $protocol = Protocol::HTTP): self
    {
        return new static(sprintf('Bad Request: `%s`', $message), $protocol, 400);
    }
1085749
public static function parse(string $uri): Uri
    {
        preg_match(static::URI_PATTERN, $uri, $matches);

        $components = static::componentsFromMatches($matches);
        $scheme = $components['scheme'];
        $authority = $components['authority'];
        $path = $components['path'];
        $query = $components['query'];
        $fragment = $components['fragment'];

        return new static($path, $scheme, $authority, $query, $fragment);
    }
1017389
public function withUri(UriInterface $uri, $preserveHost = false)
    {
        $request = $this->copy();
        $request->uri = $uri;
        
        if (!$preserveHost) {
            $request = $request->withHeader('Host', $request->uri->getHost());
        }
        
        return $request;
    }
926637
public function withUri(UriInterface $uri, $preserveHost = false)
    {
        $clone = $this->_clone('uri', $uri);

        if ($preserveHost === true || $uri->getHost() === null) {

            return $clone;
        }

        $clone->headers['host'] = $uri->getHost();

        return $clone;

    }
599401
public function setProtocol($protocol) {

        if ( empty($protocol) || !in_array($protocol, $this->supported_protocols) ) throw new InvalidArgumentException('Invalid or unsupported RPC protocol');

        $this->protocol = $protocol;

        return $this;

    }