This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: BaseHTTPServer subclass I/O call blocks forever
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum
Priority: normal Keywords:

Created on 2000-11-18 08:14 by anonymous, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (3)
msg2444 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-11-18 08:14
The following BaseHTTPServer subclass blocks in the do_POST() method under Python 2.0, 1.5.2 (on Windows NT and Linux) and JPython 1.1+09.  It seems to block in the write() calls after the read() call.




import BaseHTTPServer 
 
 
class VASTestHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 
 
    contentType="text/html" 
 
    htmlForm="<FORM METHOD=POST ACTION=/handler>\r\n<br>NAME:&nbsp;<INPUT TYPE=\
TEXT NAME=name></INPUT><br><INPUT TYPE=SUBMIT></INPUT><p>\r\n</FORM>\r\n" 
    rspGETContent="<HTML>\r\n<HEAD>\r\n</HEAD>\r\n<BODY>\r\n<H1>GET</H1>\r\n%s<\
/BODY>\r\n</HTML>\r\n" 
 
    rspPOSTContent="\r\n\r\n<HTML>\r\n<HEAD>\r\n</HEAD>\r\n<BODY>\r\n<H1>POST</\
H1>\r\n%s</BODY>\r\n</HTML>\r\n" 
 
    def do_GET(self): 
        self.send_head() 
        self.wfile.write(self.rspGETContent % (self.htmlForm)) 
         
    def do_HEAD(self): 
        self.send_head() 
    def do_POST(self): 
        self.log_message("%s","Processing POST  ...") 
        self.log_message("%s",self.rspPOSTContent % (self.htmlForm)) 
        self.contentLength=int(self.headers.getheader("Content-Length")) 
        self.log_message("content-length=%d",self.contentLength) 
 
        # this read blocks forever 
        self.reqContent=self.rfile.read() 
        self.log_message("%s",self.reqContent) 
 
        self.send_head() 
        self.wfile.write(self.rspPOSTContent % (self.htmlForm)) 
        self.log_message("%s","Processed POST") 
         
    def send_head(self): 
        self.send_response(200) 
        self.send_header("Content-Type",self.contentType) 
        self.send_header("Expires","0") 
        self.end_headers() 
 
    def setContentType(self,type): 
        self.contentType=type 
 
 
def test(HandlerClass = VASTestHTTPRequestHandler, 
         ServerClass = BaseHTTPServer.HTTPServer): 
    port=8888 
    serverAddress=('',port) 
    httpd = ServerClass(serverAddress, HandlerClass) 
 
    print "Serving HTTP on port", port, "..." 
    httpd.serve_forever() 
 
 
if __name__ == '__main__': 
    test() 
 
msg2445 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-11-27 21:13
As the author of said module I'll look at this.
msg2446 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-11-27 21:16
This is a bug in the test code. You call self.rfile.read(), which attempts to read until it sees an EOF. Not all browsers send an EOF. To fix, use self.rfile.read(self.contentLength) instead.
History
Date User Action Args
2022-04-10 16:03:30adminsetgithub: 33492
2000-11-18 08:14:12anonymouscreate