Avoid hangs when handling of HTTP POST requests

Kaloian Doganov <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
I am using PyBlosxom with bozohttpd [1] -- a small and featureless HTTP
server launched from inetd.  When serving requests to CGI scripts,
bozohttpd does not send EOF at the end of the body.  Although
inconvenient, this behaviour is compliant to CGI 1.1 specification [2]:

    The server will send CONTENT_LENGTH bytes on this file
    descriptor. Remember that it will give the CONTENT_TYPE of the data
    as well. The server is in no way obligated to send end-of-file after
    the script reads CONTENT_LENGTH bytes.

This causes PyBlosxom to hang when serving POST requests (very common
when comments plugin is used).  This is the same problem described in
bug #1184799 [3], just experienced with different HTTP server --
bozohttpd instead of Twisted.


[1] http://www.eterna.com.au/bozohttpd/
[2] http://hoohoo.ncsa.uiuc.edu/cgi/in.html
[3] http://sourceforge.net/tracker/index.php?func=detail&aid=1184799&group_id=67445&atid=517918

So, I suggest the following patch:

Index: pyblosxom.py
===================================================================
RCS file: /cvsroot/pyblosxom/pyblosxom/Pyblosxom/pyblosxom.py,v
retrieving revision 1.72
diff -U3 -r1.72 pyblosxom.py
--- pyblosxom.py        7 Oct 2005 22:48:32 -0000       1.72
+++ pyblosxom.py        8 Oct 2005 23:56:43 -0000
@@ -448,12 +448,13 @@
         pyhttp = self.getHttp()
         input = pyhttp['wsgi.input']
         method = pyhttp["REQUEST_METHOD"]
+        length = pyhttp["CONTENT_LENGTH"]

         # there's no data on stdin for a GET request.  pyblosxom
         # will block indefinitely on the read for a GET request with
         # thttpd.
         if method != "GET":
-            self._in.write(input.read())
+            self._in.write(input.read(length))
             # rewind to start
             self._in.seek(0)


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.