diff --git a/src/Pecee/Http/Request.php b/src/Pecee/Http/Request.php index 399bfdb..100cd38 100644 --- a/src/Pecee/Http/Request.php +++ b/src/Pecee/Http/Request.php @@ -395,10 +395,6 @@ public function setUrl(Url $url): void { $this->url = $url; - if ($this->url->getHost() === null && $this->getHost() !== null) { - $this->url->setHost((string)$this->getHost()); - } - if ($this->isSecure() === true) { $this->url->setScheme('https'); } diff --git a/src/Pecee/Http/Url.php b/src/Pecee/Http/Url.php index e32f23b..4bd2647 100644 --- a/src/Pecee/Http/Url.php +++ b/src/Pecee/Http/Url.php @@ -144,10 +144,15 @@ public function setScheme(string $scheme): self /** * Get url host * + * @param bool $includeTrails Prepend // in front of hostname * @return string|null */ - public function getHost(): ?string + public function getHost(bool $includeTrails = false): ?string { + if ((string)$this->host !== '' && $includeTrails === true) { + return '//' . $this->host; + } + return $this->host; } @@ -530,12 +535,12 @@ public function getAbsoluteUrl(bool $includeParams = true): string */ public function jsonSerialize(): string { - return $this->getRelativeUrl(); + return $this->getHost(true) . $this->getRelativeUrl(); } public function __toString(): string { - return $this->getRelativeUrl(); + return $this->getHost(true) . $this->getRelativeUrl(); } } \ No newline at end of file