[Zope-dev] ZServer FastCGI patch for IRIX (and others?)

Phillip J. Eby pje@telecommunity.com
Thu, 18 Nov 1999 17:15:25 -0500


Below is a patch to let ZServer's FastCGI support work with FastCGI client
implementations that don't properly close the STDIN sub-stream.  On the
IRIX/Apache/cgi-fcgi combo used where I work, the client side doesn't seem
to know when it's done sending STDIN data, and thus the ZServer side simply
hangs forever waiting for it.  The patch below makes ZServer ignore STDIN
altogether if there is no Content-Length, and also stop looking for more
STDIN data if Content-Length or more bytes have already been read.


--- FCGIServer.py       Thu Nov 18 17:08:24 1999
+++ Zope2/ZServer/FCGIServer.py Thu Nov 18 17:05:02 1999
@@ -429,6 +429,8 @@
         elif rec.recType == FCGI_PARAMS:
             if rec.contentLength == 0:  # end of the stream
                 self.remainingRecs = self.remainingRecs - 1
+
self.content_length=string.atoi(self.env.get('CONTENT_LENGTH','0'))
+               if self.content_length==0: self.remainingRecs =
self.remainingRecs - 1
             else:
                 self.env.update(rec.values)
 
@@ -438,6 +440,8 @@
                 self.remainingRecs = self.remainingRecs - 1
             else:
                 self.stdin.write(rec.content)
+               self.content_length = self.content_length - rec.contentLength
+               if self.content_length<=0: self.remainingRecs =
self.remainingRecs - 1
 
         # read some filter data
         elif rec.recType == FCGI_DATA:
@@ -448,7 +452,7 @@
 
 
         # We've processed the record.  Now what do we do?
-        if self.remainingRecs:
+        if self.remainingRecs > 0:
             # prepare to get the next record
             self.setInitialState()