Exemple #1
0
 def handle(self, client, addr):
     self.close_on_exec(client)
     try:
         req = http.HTTPRequest(client, addr, self.address)
         response = self.app(req.read(), req.start_response)
         http.HTTPResponse(client, response, req).send()
     except Exception, e:
         self.log.exception("Error processing request. [%s]" % str(e))
         # try to send something if an error happend
         msg = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
         util.write_nonblock(client, msg)
         util.close(client)
Exemple #2
0
            parser = http.RequestParser(client)
            req = parser.next()
            self.handle_request(req, client, addr)
        except StopIteration:
            self.log.debug("Ignored premature client disconnection.")
        except socket.error, e:
            if e[0] != errno.EPIPE:
                self.log.exception("Error processing request.")
            else:
                self.log.debug("Ignoring EPIPE")
        except Exception, e:
            self.log.exception("Error processing request.")
            try:
                # Last ditch attempt to notify the client of an error.
                mesg = "HTTP/1.1 500 Internal Server Error\r\n\r\n"
                util.write_nonblock(client, mesg)
            except:
                pass
        finally:
            util.close(client)

    def handle_request(self, req, client, addr):
        try:
            debug = self.cfg.debug or False
            resp, environ = wsgi.create(req, client, addr, self.address, self.cfg)
            respiter = self.wsgi(environ, resp.start_response)
            for item in respiter:
                resp.write(item)
            resp.close()
            if hasattr(respiter, "close"):
                respiter.close()