diff options
-rw-r--r-- | catalog/middleware.py | 10 | ||||
-rw-r--r-- | catalog/settings.py | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/catalog/middleware.py b/catalog/middleware.py index cd6aa8b..02d4740 100644 --- a/catalog/middleware.py +++ b/catalog/middleware.py @@ -11,12 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import uuid + from onaplogging.mdcContext import MDC from catalog.pub.config.config import FORWARDED_FOR_FIELDS, SERVICE_NAME class LogContextMiddleware(object): + def __init__(self, get_response): + self.get_response = get_response + # the last IP behind multiple proxies, if no exist proxies # get local host ip. def _getLastIp(self, request): @@ -58,3 +62,9 @@ class LogContextMiddleware(object): def process_response(self, request, response): MDC.clear() return response + + def __call__(self, request): + self.process_request(request) + response = self.get_response(request) + self.process_response(request, response) + return response diff --git a/catalog/settings.py b/catalog/settings.py index 0068dac..cbb90d7 100644 --- a/catalog/settings.py +++ b/catalog/settings.py @@ -80,13 +80,12 @@ TEMPLATES = [ }, ] -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'catalog.middleware.LogContextMiddleware', |