]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Retrospectively fix code to handle IE's additional characters on certain
authorSteve Holden <steve@holdenweb.com>
Wed, 8 Jan 2003 21:17:35 +0000 (21:17 +0000)
committerSteve Holden <steve@holdenweb.com>
Wed, 8 Jan 2003 21:17:35 +0000 (21:17 +0000)
web transactions more gracefully (through a fairly ugly hack). See bugs
430610 and 427345.

Lib/CGIHTTPServer.py

index 2106a5397260e96d733390e02da3c54458d4ea96..970572be6d22cb5e7d5bfa9849baefa5c427dbf1 100644 (file)
@@ -26,6 +26,7 @@ import sys
 import urllib
 import BaseHTTPServer
 import SimpleHTTPServer
+import select
 
 
 class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
@@ -199,6 +200,9 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
             if pid != 0:
                 # Parent
                 pid, sts = os.waitpid(pid, 0)
+                # throw away additional data [see bug #427345]
+                while select.select([self.rfile], [], [], 0)[0]:
+                    waste = self.rfile.read(1)
                 if sts:
                     self.log_error("CGI script exit status %#x", sts)
                 return
@@ -244,6 +248,9 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
             if self.command.lower() == "post" and nbytes > 0:
                 data = self.rfile.read(nbytes)
                 fi.write(data)
+            # throw away additional data [see bug #427345]
+            while select.select([self.rfile._sock], [], [], 0)[0]:
+                waste = self.rfile._sock.recv(1)
             fi.close()
             shutil.copyfileobj(fo, self.wfile)
             if self.have_popen3: