From d5bd7602890b77b0081f65a37387c01737ad2574 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 12 Jul 2013 22:38:50 +0200 Subject: [PATCH] Fixed HTTPRequest sending a wrong Host-header after 3xx received --- .../install/files/lib/util/HTTPRequest.class.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index 909ac08ba2..e22a851256 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -127,8 +127,6 @@ final class HTTPRequest { * @param string $url */ private function setURL($url) { - $this->url = $url; - if (PROXY_SERVER_HTTP) { $parsedUrl = parse_url(PROXY_SERVER_HTTP); $this->path = $url; @@ -137,11 +135,19 @@ final class HTTPRequest { $parsedUrl = parse_url($url); $this->path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '/'; } + $this->useSSL = $parsedUrl['scheme'] === 'https'; $this->host = $parsedUrl['host']; $this->port = isset($parsedUrl['port']) ? $parsedUrl['port'] : ($this->useSSL ? 443 : 80); $this->path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '/'; $this->query = isset($parsedUrl['query']) ? $parsedUrl['query'] : ''; + + // update the 'Host:' header if URL has changed + if (!empty($this->url) && $this->url != $url) { + $this->addHeader('Host', $this->host.($this->port != ($this->useSSL ? 443 : 80) ? ':'.$this->port : '')); + } + + $this->url = $url; } /** @@ -162,6 +168,7 @@ final class HTTPRequest { $request .= "\r\n"; // add post parameters if ($this->options['method'] !== 'GET') $request .= http_build_query($this->postParameters, '', '&')."\r\n\r\n"; + $remoteFile->puts($request); $inHeader = true; @@ -239,6 +246,7 @@ final class HTTPRequest { } try { + echo "
new location: ".$this->replyHeaders['Location']."
"; $newRequest->setURL($this->replyHeaders['Location']); } catch (SystemException $e) { -- 2.20.1