SVN: r22403 - trunk/quixote/server

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 04 Sep 2003 13:20:02 -0400
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2003-09-04 13:20:02 -0400 (Thu, 04 Sep 2003)
New Revision: 22403

Modified:
   trunk/quixote/server/medusa_http.py
Log:
Strip fragments from URLs (some versions of MSIE incorrectly send them
at certain times; for example, a redirect includes them).

Also, make REQUEST_URI contain the URI, not just the path.


Modified: trunk/quixote/server/medusa_http.py
===================================================================
--- trunk/quixote/server/medusa_http.py	2003-09-04 17:03:27 UTC (rev 22402)
+++ trunk/quixote/server/medusa_http.py	2003-09-04 17:20:02 UTC (rev 22403)
@@ -9,6 +9,7 @@
 
 # A simple HTTP server, using Medusa, that publishes a Quixote application.
 
+import sys
 import asyncore, rfc822, socket
 from StringIO import StringIO
 from medusa import http_server, xmlrpc_handler
@@ -56,9 +57,14 @@
     def continue_request (self, data, request):
         msg = rfc822.Message(StringIO('\n'.join(request.header)))
         remote_addr, remote_port = request.channel.addr
-        query_string = ''
+        if '#' in request.uri:
+            # MSIE is buggy and sometimes includes fragments in URLs
+            [request.uri, fragment] = request.uri.split('#', 1)
         if '?' in request.uri:
-            [request.uri, query_string] = request.uri.split('?', 1)
+            [path, query_string] = request.uri.split('?', 1)
+        else:
+            path = request.uri
+            query_string = ''
 
         environ = {'REQUEST_METHOD': request.command,
                    'ACCEPT_ENCODING': msg.get('Accept-encoding'),
@@ -68,7 +74,7 @@
                    'HTTP_COOKIE': msg.get('Cookie'),
                    'HTTP_REFERER': msg.get('Referer'),
                    'HTTP_USER_AGENT': msg.get('User-agent'),
-                   'PATH_INFO': request.uri,
+                   'PATH_INFO': path,
                    'QUERY_STRING': query_string,
                    'REMOTE_ADDR': remote_addr,
                    'REMOTE_PORT': str(remote_port),
@@ -125,8 +131,12 @@
     from quixote import enable_ptl
     enable_ptl()
 
-    print 'Now serving the Quixote demo on port 8080'
-    server = http_server.http_server('', 8080)
+    if len(sys.argv) == 2:
+        port = int(sys.argv[1])
+    else:
+        port = 8080
+    print 'Now serving the Quixote demo on port %d' % port
+    server = http_server.http_server('', port)
     publisher = Publisher('quixote.demo')
 
     # When initializing the Publisher in your own driver script,