views:

31

answers:

0

I want to write a simple FastCGI server and I decided to use flup python module. The problem is that I need to send a HTTP client real 4xx and 5xx error status codes if something goes wrong but flup's WSGIServer sends 200 status code and some fancy formatted stack trace. Finally I've figured out how not to send to the client that stack trace -- you need to redefine error(self, req) method:

class MyWSGIServer(WSGIServer):
    def error(self, req):
        req.stdout.write('Content-Type: text/plain\r\n\r\nFAILED\n')

but I still don't know how not to send 200 status code in case of some trouble with my FastCGI server and send real 4xx or 5xx codes.