From d6012fa84b6f86cbd5d4e5010856b0f8da9bd643 Mon Sep 17 00:00:00 2001 From: benoitc Date: Fri, 16 Mar 2012 07:18:30 +0100 Subject: [PATCH] fix gevent_pywsgi worker. close #314 access_log arity has changed in 0.14.0. Apply this change to the pywsgi worker as well. --- gunicorn/glogging.py | 7 ++++++- gunicorn/workers/ggevent.py | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py index ad2f57c4..fea26016 100644 --- a/gunicorn/glogging.py +++ b/gunicorn/glogging.py @@ -175,7 +175,12 @@ class Logger(object): } # add request headers - atoms.update(dict([("{%s}i" % k.lower(),v) for k, v in req.headers])) + if hasattr(req, 'headers'): + req_headers = req.headers + else: + req_headers = req + + atoms.update(dict([("{%s}i" % k.lower(),v) for k, v in req_headers])) # add response headers atoms.update(dict([("{%s}o" % k.lower(),v) for k, v in resp.headers])) diff --git a/gunicorn/workers/ggevent.py b/gunicorn/workers/ggevent.py index 4ad6ef32..c8a42eb0 100644 --- a/gunicorn/workers/ggevent.py +++ b/gunicorn/workers/ggevent.py @@ -96,13 +96,29 @@ class GeventWorker(AsyncWorker): gevent.core.dns_init() super(GeventWorker, self).init_process() + +class GeventResponse(object): + + status = None + headers = None + response_length = None + + + def __init__(self, status, headers, clength): + self.status = status + self.headers = headers + self.response_length = clength + class PyWSGIHandler(pywsgi.WSGIHandler): def log_request(self): start = datetime.fromtimestamp(self.time_start) finish = datetime.fromtimestamp(self.time_finish) response_time = finish - start - self.server.log.access(self, self.environ, response_time) + resp = GeventResponse(self.status, self.response_headers, + self.response_length) + req_headers = [h.split(":", 1) for h in self.headers.headers] + self.server.log.access(resp, req_headers, self.environ, response_time) def get_environ(self): env = super(PyWSGIHandler, self).get_environ()