Fixed HTTPRequest sending a wrong Host-header after 3xx received
authorAlexander Ebert <ebert@woltlab.com>
Fri, 12 Jul 2013 20:38:50 +0000 (22:38 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 12 Jul 2013 20:38:50 +0000 (22:38 +0200)
wcfsetup/install/files/lib/util/HTTPRequest.class.php

index 909ac08ba2cdee090421ea07648b10a6849a3224..e22a8512565aeac57f4df3f5016e4b8320e7a396 100644 (file)
@@ -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 "<pre>new location: ".$this->replyHeaders['Location']."</pre>";
                                        $newRequest->setURL($this->replyHeaders['Location']);
                                }
                                catch (SystemException $e) {