[Web-SIG] Updated WSGIHTTPServer.py

Phillip J. Eby pje at telecommunity.com
Thu Sep 23 04:41:49 CEST 2004


 >I've updated WSGIHTTPServer.py and wsgicgi.py to reflect the latest
 >PEP posted on python.org.
 >
 >http://st0rm.hopto.org/wsgi/

FYI, there's an error in your WSGIHTTPServer implementation: it sends a 
'Status: XXX etc' header to the client, but the correct format for HTTP is 
just the "XXX etc" part.  Looks like you might've copied that part from the 
PEP's CGI example.  This error is probably being masked by the fact that 
you're also sending the status to the client when start_response is 
initially called, rather than delaying until the first write operation or 
non-empty yielded string.  Also, 'start_response' doesn't actually re-raise 
'exc_info' as it should; it only prints the exception to stderr.

You should also not use 'map()' to wrap the application result 
iterator.  It's not illegal, but it's ill-advised since an application is 
allowed to produce an unlimited number of empty strings in its output, 
resulting in unbounded growth of the list that could use up arbitrarily 
large amounts of memory.

Finally, while this is not a violation of the spec in any way, I notice 
that your approach to loading application scripts will recompile and reload 
them on every hit.  I don't know if this was intentional or not.

Oh, and one last thing...  you're checking for 'HTTPS=on' in the 
environment, but that's not where it would be found, because your code is 
the only code that could set it.  I don't know if the stdlib HTTP server 
supports HTTPS, but if it does, you should check the appropriate attribute 
or method instead.  Otherwise, it suffices to always set 'wsgi.url_scheme' 
to "http".



More information about the Web-SIG mailing list