From dfdc34603e3091780ae1ce9e826c653f4cf41c40 Mon Sep 17 00:00:00 2001 From: Reid Barton Date: Wed, 19 Aug 2015 13:20:27 -0700 Subject: [PATCH] Django 1.7 compatibility: handle both response.content and response.streaming_content (imported from commit faaaff96819731a334d52b7d715c8ddb7c0d4293) --- zerver/middleware.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zerver/middleware.py b/zerver/middleware.py index 26e1f1bda3..a1f4073d7d 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -83,7 +83,7 @@ def is_slow_query(time_delta, path): return True def write_log_line(log_data, path, method, remote_ip, email, client_name, - status_code=200, error_content=''): + status_code=200, error_content_iter=()): # For statsd timer name if path == '/': statsd_path = 'webreq' @@ -191,6 +191,7 @@ def write_log_line(log_data, path, method, remote_ip, email, client_name, # Log some additional data whenever we return certain 40x errors if 400 <= status_code < 500 and status_code not in [401, 404, 405]: + error_content = ''.join(error_content_iter) if len(error_content) > 100: error_content = "[content more than 100 characters]" logger.info('status=%3d, data=%s, uid=%s' % (status_code, error_content, email)) @@ -233,9 +234,14 @@ class LogRequests(object): except Exception: client = "?" + if response.streaming: + content_iter = response.streaming_content + else: + content_iter = (response.content,) + write_log_line(request._log_data, request.path, request.method, remote_ip, email, client, response.status_code, - response.content) + content_iter) return response class JsonErrorHandler(object):