SVN: r23569 - trunk/quixote/server

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 25 Feb 2004 12:23:27 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-02-25 12:23:27 -0500 (Wed, 25 Feb 2004)
New Revision: 23569

Modified:
   trunk/quixote/server/medusa_http.py
Log:
If "Host" header is present, use it to set SERVER_NAME and
SERVER_PORT.


Modified: trunk/quixote/server/medusa_http.py
===================================================================
--- trunk/quixote/server/medusa_http.py	2004-02-25 17:18:49 UTC (rev 23568)
+++ trunk/quixote/server/medusa_http.py	2004-02-25 17:23:27 UTC (rev 23569)
@@ -65,6 +65,17 @@
             path = request.uri
             query_string = ''
 
+        server_port = str(self.server.port),
+        http_host = msg.get("Host")
+        if http_host:
+            if ":" in http_host:
+                server_name, server_port = http_host.split(":", 1)
+            else:
+                server_name = http_host
+        else:
+            server_name = (self.server.ip or
+                           socket.gethostbyaddr(socket.gethostname())[0])
+
         environ = {'REQUEST_METHOD': request.command,
                    'ACCEPT_ENCODING': msg.get('Accept-encoding'),
                    'CONTENT_TYPE': msg.get('Content-type'),
@@ -80,11 +91,12 @@
                    'REQUEST_URI': request.uri,
                    'SCRIPT_NAME': '',
                    "SCRIPT_FILENAME": '',
-                   'SERVER_NAME': self.server.ip or socket.gethostname(),
-                   'SERVER_PORT': str(self.server.port),
+                   'SERVER_NAME': server_name,
+                   'SERVER_PORT': server_port,
                    'SERVER_PROTOCOL': 'HTTP/1.1',
                    'SERVER_SOFTWARE': self.server_name,
                    }
+        
         # Propagate HTTP headers - copied from twisted_http.py
         for title, header in msg.items():
             envname = title.replace('-', '_').upper()