src/Request.php
protected function setUri($uri, $preserveHost = false)
    {
        if (is_string($uri)) {
            $uri = new Uri($uri);
        }
        if (! $uri instanceof UriInterface) {
            throw new InvalidArgumentException(sprintf(
                'Invalid URI provided. Must be null, a string, or '
                . 'Psr\Http\Message\UriInterface; received "%s".',
                is_object($uri) ? get_class($uri) : gettype($uri)
            ));
        }
        $this->uri = $uri;

        if ($preserveHost && $this->hasHeader('Host')) {
            return $this;
        }

        if (! $uri->getHost()) {
            return $this;
        }

        $host = $uri->getHost();
        if ($uri->getPort()) {
            $host .= ':' . $uri->getPort();
        }
        $this->setHeader('Host', $host);

        return $this;
    }
protected function setUri($uri, $preserveHost = false)
    {
        if (is_string($uri)) {
            $uri = new Uri($uri);
        }
        if (! $uri instanceof UriInterface) {
            throw new InvalidArgumentException(sprintf(
                'Invalid URI provided. Must be null, a string, or '
                . 'Psr\Http\Message\UriInterface; received "%s".',
                is_object($uri) ? get_class($uri) : gettype($uri)
            ));
        }
        $this->uri = $uri;

        if ($preserveHost && $this->hasHeader('Host')) {
            return $this;
        }

        if (! $uri->getHost()) {
            return $this;
        }

        $host = $uri->getHost();
        if ($uri->getPort()) {
            $host .= ':' . $uri->getPort();
        }
        $this->setHeader('Host', $host);

        return $this;
    }
protected function setUri ( $ uri , $ preserveHost = false ) { if ( is_string ( $ uri ) ) { $ uri = new Uri ( $ uri ) ; } if ( ! $ uri instanceof UriInterface ) { throw new InvalidArgumentException ( sprintf ( 'Invalid URI provided. Must be null, a string, or ' . 'Psr\Http\Message\UriInterface; received "%s".' , is_object ( $ uri ) ? get_class ( $ uri ) : gettype ( $ uri ) ) ) ; } $ this -> uri = $ uri ; if ( $ preserveHost && $ this -> hasHeader ( 'Host' ) ) { return $ this ; } if ( ! $ uri -> getHost ( ) ) { return $ this ; } $ host = $ uri -> getHost ( ) ; if ( $ uri -> getPort ( ) ) { $ host .= ':' . $ uri -> getPort ( ) ; } $ this -> setHeader ( 'Host' , $ host ) ; return $ this ; }
Sets the URI.

@param string|\Psr\Http\Message\UriInterface $uri The URI

If the URI contains a host component, the Host header will update. You
can opt-in to preserving the original state of the Host header by
setting `$preserveHost` to `true`.
@param bool $preserveHost Preserve the original state of the Host header

@throws \InvalidArgumentException If Invalid URI provided

@return self
Sets the URI .