Properly set the Host header to target host instead of proxy host
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 19 Nov 2014 03:03:57 +0000 (04:03 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 19 Nov 2014 03:44:12 +0000 (04:44 +0100)
wcfsetup/install/files/lib/util/HTTPRequest.class.php

index d98758be30ee69c2f4a328c332ed6fd8226b2c7e..591c4628386c2d204a61972156058af37ffa2e4c 100644 (file)
@@ -191,7 +191,6 @@ final class HTTPRequest {
                if (isset($this->options['auth'])) {
                        $this->addHeader('authorization', "Basic ".base64_encode($options['auth']['username'].":".$options['auth']['password']));
                }
-               $this->addHeader('host', $this->host.($this->port != ($this->useSSL ? 443 : 80) ? ':'.$this->port : ''));
                $this->addHeader('connection', 'Close');
        }
        
@@ -201,12 +200,12 @@ final class HTTPRequest {
         * @param       string          $url
         */
        private function setURL($url) {
+               $parsedUrl = $originUrl = parse_url($url);
                if (PROXY_SERVER_HTTP) {
                        $parsedUrl = parse_url(PROXY_SERVER_HTTP);
                        $this->path = $url;
                }
                else {
-                       $parsedUrl = parse_url($url);
                        $this->path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '/';
                }
                
@@ -216,8 +215,11 @@ final class HTTPRequest {
                $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 : ''));
+               if ($this->url != $url) {
+                       $originUseSSL = $originUrl['scheme'] === 'https';
+                       $originHost = $originUrl['host'];
+                       $originPort = isset($originUrl['port']) ? $originUrl['port'] : ($originUseSSL ? 443 : 80);
+                       $this->addHeader('host', $originHost.($originPort != ($originUseSSL ? 443 : 80) ? ':'.$originPort : ''));
                }
                
                $this->url = $url;