Small fix in Header netloc master
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 24 Feb 2011 15:03:10 +0000 (15:03 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 24 Feb 2011 15:03:10 +0000 (15:03 +0000)
sproxy

diff --git a/sproxy b/sproxy
index 76fd2a7dcd81f41024f770c33fb59e12096a7861..dc18be47a9e97e66533baf26b52220db2d0e121a 100755 (executable)
--- a/sproxy
+++ b/sproxy
@@ -303,24 +303,28 @@ class HttpRequest(HttpBase):
             return result
 
         if self.parsed_url.scheme and not self.parsed_url.netloc:
-            self.parsed_url = urlparse.ParseResult('', self.parsed_url.scheme, *self.parsed_url[2:])
             logging.debug('emptying scheme for netloc')
+            self.parsed_url = urlparse.ParseResult('', self.parsed_url.scheme, *self.parsed_url[2:])
 
         request_hostname = self.parsed_url.hostname
         request_port = self.parsed_url.port
         request_netloc = join_it(request_hostname, request_port)
         header_necloc = self.get_header_value('Host')
-        header_hostname, header_port = split_it(header_necloc)
+        if header_necloc:
+            header_hostname, header_port = split_it(header_necloc)
+        else:
+            header_hostname, header_port = None, None
+
         if not request_hostname and header_hostname:
             # copy "Host" header into request netloc
             self.parsed_url = urlparse.ParseResult(self.parsed_url.scheme, header_hostname, *self.parsed_url[2:])
         elif request_hostname:
-            if request_netloc != header_necloc:
+            if request_netloc != header_necloc and header_necloc:
                 # RFC 2616, section 5.2: Host header must be ignored FIXME
                 logging.warning('Ignoring necloc value %s in request. Header "Host" value is %s', request_netloc, header_necloc)
                 for i in range(len(self.headers)):
                     if self.headers[i][0].lower()=='host':
-                        self.headers[i] = ('Host', 'request_netloc')
+                        self.headers[i] = ('Host', request_netloc)
                 # Patch header here
             elif not header_necloc:
                 self.headers.append(('Host', request_netloc))